Bug 7249 - Yesterday's builds filter shows today's builds instead of yesterday's
Summary: Yesterday's builds filter shows today's builds instead of yesterday's
Status: VERIFIED FIXED
Alias: None
Product: Toaster
Classification: Build System, Metadata & Runtime
Component: toaster (show other bugs)
Version: unspecified
Hardware: x86 Multiple
: Medium normal
Target Milestone: 1.8 M4
Assignee: David Reyna
QA Contact: Alexandru Roman
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2015-01-26 11:34 UTC by Belen Barros Pena
Modified: 2015-11-26 14:47 UTC (History)
7 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: No (bug/feature does not impact docs)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Belen Barros Pena 2015-01-26 11:34:36 UTC
This happens both in:

- the all builds table
- the project builds table

To reproduce, build something with Toaster. Once the build is done, go to the all builds table and open the completed on filters. Select the 'yesterday's builds' option. You will see the build you just run listed there.
Comment 1 David Reyna 2015-03-15 07:37:07 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()),
Comment 2 David Reyna 2015-03-15 07:41:37 UTC
( 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)
Comment 3 Alexandru Roman 2015-11-26 14:47:26 UTC
Verified.