dev:index
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
dev:index [2015/02/16 15:21] – kobe | dev:index [2021/09/02 14:38] (current) – aggiunta problematica di conversione timestamps feroda | ||
---|---|---|---|
Line 3: | Line 3: | ||
Questa pagina è il magazzino per le informazioni degli sviluppatori. | Questa pagina è il magazzino per le informazioni degli sviluppatori. | ||
- | * [[dev: | + | * [[dev: |
- | * [[http:// | + | * [[git-forking-workflow|Git Forking Workflow]] |
- | * [[http:// | + | * [[release-management|Release Management]] |
+ | * [[coding-styleguide|Coding Styleguide]] | ||
- | ===== Single Page App - JavaScript ===== | ||
- | * [[http:// | + | ====== Ora qui appunto sul tempo e python... ====== |
- | * [[http:// | + | |
- | * [[http:// | + | |
- | * Le promises spiegate tramite vignette: | + | |
- | **Mobile** | + | Parliamo della conversione tra Unix Timestamp e Date time con Timezone, in Django e in SQL. |
- | * [[https:// | + | Output di un codice di test nella piattaforma '' |
- | * [[https:// | + | |
- | * [[http:// | + | |
- | ===== Guide specifiche ===== | + | |
- | * [[release-management|Release Management]] | + | < |
- | | + | --- |
+ | Testing timestamps datetime conversions.. | ||
+ | UNIX TIMESTAMP ts = 1 | ||
+ | --- | ||
+ | [UNAWARE] fromtimestamp = dtunaware = datetime.datetime(1970, | ||
+ | [UNAWARE] dtunaware.strftime(" | ||
+ | [UNAWARE] defaultfilters.date(dtunaware, | ||
+ | [UNAWARE] EXTRACT EPOCH dtunaware_metrics[0][" | ||
+ | --- | ||
+ | [AWARE] fromtimestamp.replace(tzinfo=UTC): | ||
+ | [AWARE] dtaware.strftime(" | ||
+ | [AWARE] defaultfilters.date(dtaware, | ||
+ | [AWARE] EXTRACT EPOCH dtaware_metrics[0][" | ||
+ | --- | ||
+ | [UTC] utcfromtimestamp: | ||
+ | [UTC] utcdt.strftime(" | ||
+ | [UTC] defaultfilters.date(utcdt, | ||
+ | [UTC] EXTRACT EPOCH utcdt_metrics[0][" | ||
+ | |||
+ | </ | ||
+ | |||
+ | Codice per riprodurre questo output nella shell Django '' | ||
+ | |||
+ | < | ||
+ | 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, | ||
+ | m.objects.create(time=dtaware, | ||
+ | m.objects.create(time=dtunaware, | ||
+ | |||
+ | dtunaware_metrics = m.objects.filter(time=dtunaware).annotate(ts=Extract(" | ||
+ | dtaware_metrics = m.objects.filter(time=dtaware).annotate(ts=Extract(" | ||
+ | utcdt_metrics = m.objects.filter(time=utcdt).annotate(ts=Extract(" | ||
+ | |||
+ | |||
+ | print(" | ||
+ | print(f" | ||
+ | print(f" | ||
+ | |||
+ | print(" | ||
+ | print(f" | ||
+ | print(f' | ||
+ | print(f' | ||
+ | print(f' | ||
+ | |||
+ | print(" | ||
+ | print(f" | ||
+ | print(f' | ||
+ | print(f' | ||
+ | print(f' | ||
+ | |||
+ | print(" | ||
+ | print(f" | ||
+ | print(f' | ||
+ | print(f' | ||
+ | print(f' | ||
+ | </ | ||
+ | |||
+ | Benedette siano le f-strings per il debug! |
dev/index.1424100064.txt.gz · Last modified: 2015/02/16 15:21 by kobe