| Summary: | Yesterday's builds filter shows today's builds instead of yesterday's | ||
|---|---|---|---|
| Product: | [Build System, Metadata & Runtime] Toaster | Reporter: | Belen Barros Pena <belen.barros.pena> |
| Component: | toaster | Assignee: | David Reyna <david.reyna> |
| Status: | VERIFIED FIXED | QA Contact: | Alexandru Roman <alexandru.costinx.roman> |
| Severity: | normal | ||
| Priority: | Medium | CC: | alexandru.costinx.roman, alexandru.damian, belen.barros.pena, bluelightning, cristiana.voicu, dave.lerner, jessica.zhang |
| Version: | unspecified | ||
| Target Milestone: | 1.8 M4 | ||
| Hardware: | x86 | ||
| OS: | Multiple | ||
| Whiteboard: | |||
| OS type for building Yocto: | --- | Type of Regression: | --- |
| Verified: | Documentation change: | No (bug/feature does not impact docs) | |
|
Description
Belen Barros Pena
2015-01-26 11:34:36 UTC
It turns out that "today" was also broken, at least for all people outside of UTC+0 (e.g. London).
That is because "timezone.now()" is always UTC+0 regardless of the current time zone, and you have to use "timezone.localtime(timezone.now())" instead.
Also, while "strftime("%Y-%m-%d")" gives free truncation to the beginning of the day, in YP-1.8 that is for some reason no longer being used in the selector count fields for the pop-up, so it has to be compensated for.
Here is new code to calculate for both the local time zone and the explicit beginning of days.
# calculate the exact begining of local today and yesterday
today_begin = timezone.localtime(timezone.now());
todays_seconds = int(today_begin.strftime("%H"))*60*60+int(today_begin.strftime("%M"))*60+int(today_begin.strftime("%S"));
today_begin = timezone.now()-timedelta(seconds=todays_seconds);
yesterday_begin = today_begin-timedelta(days=1);
... and this example filter ...
("Today's builds" , 'created__gte:'+str(today_begin), queryset_all.filter(created__gte=today_begin).count()),
("Yesterday's builds",
'created__gte!created__lt:'
+yesterday_begin.strftime("%Y-%m-%d")+'!'
+today_begin.strftime("%Y-%m-%d"),
queryset_with_search.filter(
created__gte=yesterday_begin,
created__lt=today_begin
).count()),
( and yes I did test it watching the clock in California go from 11:59pm to 12.01am for the next day, and observe the expected shift in "today's" and "yesterday's" build counts and filtering) Verified. |