User Tools

Site Tools


dev:index

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dev:index [2015/04/22 10:07] – [Developers] mikefenderdev:index [2021/09/02 14:38] (current) – aggiunta problematica di conversione timestamps feroda
Line 4: Line 4:
  
   * [[dev:training|Training]]   * [[dev:training|Training]]
-  * [[release-management|Release Management]] 
   * [[git-forking-workflow|Git Forking Workflow]]   * [[git-forking-workflow|Git Forking Workflow]]
 +  * [[release-management|Release Management]]
 +  * [[coding-styleguide|Coding Styleguide]]
 +
 +
 +====== Ora qui appunto sul tempo e python... ======
 +
 +Parliamo della conversione tra Unix Timestamp e Date time con Timezone, in Django e in SQL.
 +
 +Output di un codice di test nella piattaforma ''my-iot-framework'':
 +
 +<code>
 +---
 +Testing timestamps datetime conversions..
 +UNIX TIMESTAMP ts = 1
 +---
 +[UNAWARE] fromtimestamp = dtunaware = datetime.datetime(1970, 1, 1, 1, 0, 1)
 +[UNAWARE] dtunaware.strftime("%s") = '1'
 +[UNAWARE] defaultfilters.date(dtunaware, "U") = '1'
 +[UNAWARE] EXTRACT EPOCH dtunaware_metrics[0]["ts"] = 3601
 +---
 +[AWARE] fromtimestamp.replace(tzinfo=UTC): dtaware = datetime.datetime(1970, 1, 1, 1, 0, 1, tzinfo=<UTC>)
 +[AWARE] dtaware.strftime("%s") = '1'
 +[AWARE] defaultfilters.date(dtaware, "U") = '3601'
 +[AWARE] EXTRACT EPOCH dtaware_metrics[0]["ts"] = 7201
 +---
 +[UTC] utcfromtimestamp: utcdt = datetime.datetime(1970, 1, 1, 0, 0, 1)
 +[UTC] utcdt.strftime("%s") = '-3599'
 +[UTC] defaultfilters.date(utcdt, "U") = '-3599'
 +[UTC] EXTRACT EPOCH utcdt_metrics[0]["ts"] = 1
 +
 +</code>
 +
 +Codice per riprodurre questo output nella shell Django ''manage.py shell'':
 +
 +<code>
 +from datetime import datetime
 +import pytz
 +
 +from django.template import defaultfilters
 +from django.db.models.functions import Extract
 +
 +from web.models import Board
 +from web.models.metrics import get_board_metric_model
 +
 +ts = 1
 +dtunaware = datetime.fromtimestamp(ts)
 +dtaware = datetime.fromtimestamp(ts).replace(tzinfo=pytz.UTC)
 +utcdt = datetime.utcfromtimestamp(ts)
 +
 +board = Board.objects.first()
 +m = get_board_metric_model(board)
 +m.objects.create(time=utcdt, data={})
 +m.objects.create(time=dtaware, data={})
 +m.objects.create(time=dtunaware, data={})
  
-Varie:+dtunaware_metrics = m.objects.filter(time=dtunaware).annotate(ts=Extract("time", "epoch")).values() 
 +dtaware_metrics = m.objects.filter(time=dtaware).annotate(ts=Extract("time", "epoch")).values() 
 +utcdt_metrics = m.objects.filter(time=utcdt).annotate(ts=Extract("time", "epoch")).values()
  
-  * [[http://www.alexefish.com/post/5234c52057d0aa0015000002|Poor developer estimations]] 
-  * [[http://getnashty.com/write-less|Write less]] 
-  * [[dev:vim|Vim]] 
  
-===== Single Page App JavaScript =====+print("---") 
 +print(f"Testing timestamps datetime conversions.."
 +print(f"UNIX TIMESTAMP {ts }")
  
-  * [[http://www.nodejs.org/|NodeJS]] - [[https://www.npmjs.com/|NPM]+print("---") 
-  [[http://bower.io/|Bower]] +print(f"[UNAWAREfromtimestamp = {dtunaware = }") 
-  [[http://jshint.com/|JSHint]], [[http://eslint.org/|ESLint]] +print(f'[UNAWARE] {dtunaware.strftime("%s") = }') 
-  * Le promises spiegate tramite vignette:  http://andyshora.com/promises-angularjs-explained-as-cartoon.html+print(f'[UNAWARE] {defaultfilters.date(dtunaware"U") = }') 
 +print(f'[UNAWARE] EXTRACT EPOCH {dtunaware_metrics[0]["ts"= }')
  
-===== Mobile =====+print("---"
 +print(f"[AWARE] fromtimestamp.replace(tzinfo=UTC): {dtaware }") 
 +print(f'[AWARE] {dtaware.strftime("%s"}') 
 +print(f'[AWARE] {defaultfilters.date(dtaware, "U"}') 
 +print(f'[AWARE] EXTRACT EPOCH {dtaware_metrics[0]["ts"}')
  
-  * [[https://cordova.apache.org/|Cordova]]/[[http://phonegap.com/|PhoneGap]] ([[http://cordova.apache.org/docs/en/4.0.0/|docs]], [[https://github.com/phonegap/phonegap/wiki|wiki]]+print("---"
-  [[https://build.phonegap.com/|PhoneGap build service]] ([[http://docs.build.phonegap.com/en_US/introduction_getting_started.md.html#Getting%20Started%20with%20Build|docs]]+print(f"[UTCutcfromtimestamp{utcdt = }") 
-  [[http://emulate.phonegap.com/|PhoneGap emulate service]] +print(f'[UTC{utcdt.strftime("%s") = }'
-  * [[http://ionicframework.com/|Ionic Framework: Angular & PhoneGap]]+print(f'[UTC] {defaultfilters.date(utcdt, "U") = }'
 +print(f'[UTC] EXTRACT EPOCH {utcdt_metrics[0]["ts"= }') 
 +</code>
  
 +Benedette siano le f-strings per il debug!
dev/index.1429697271.txt.gz · Last modified: 2015/04/22 10:07 by mikefender