summertime
Calculates the start and end of summer time in the specified year and region.
You're viewing an older version of this page (#463). View the current version.
Interface
#include <codecogs/units/time/summertime.h>
using namespace Units::Time;
Overview
\copydoc summerTimeRegion
FUNCTION
summerTime
Calculates the start and end dates for summer time in the region specified. This information can be used to adjust the local time by adding 1hr to the local time during their summer. The majority of the calculations assume that switch over between summer and winter time occurs at mid-night (12am), unless otherwise specified (see summerTimeRegion). This function returns a real number that represents the exact date and time of the switch-over, with the date represented by a serial number of Julian days with time added using a fraction of a day, i.e
References
www.webexhibits.org/daylightsaving
Example 1
#include <stdio.h>
#include <codecogs/units/time/summertime.h>
#include <codecogs/units/time/hour.h>
#include <codecogs/units/time/minute.h>
#include <codecogs/units/date/month_str.h>
#include <codecogs/units/date/month.h>
#include <codecogs/units/date/day.h>
#include <codecogs/units/date/date.h>
using namespace Units::Time;
using namespace Units::Date;
int main()
{
for(int i=2004;i<2006;i++)
{
printf("\n In year %d",i);
double start,end;
summerTime(i, start, end, st_UK);
printf("\n UK Summer time runs from %2d %s\t%2d:%02d", day(int(start)), month_str(month(int(start))), hour(start), minute(start));
printf(" to %2d %s\t%2d:%02d", day(int(end)), month_str(month(int(end))), hour(end), minute(end));
summerTime(i, start, end, st_Canada);
printf("\n Canadian Summer time runs from %2d %s\t%2d:%02d", day(int(start)), month_str(month(int(start))), hour(start), minute(start));
printf(" to %2d %s\t%2d:%02d", day(int(end)), month_str(month(int(end))), hour(end), minute(end));
}
return 0;
}Output:
In year 2004
UK Summer time runs from 28 March 1:00 to 31 October 1:00
Canadian Summer time runs from 4 April 0:00 to 31 October 0:00
In year 2005
UK Summer time runs from 27 March 1:00 to 30 October 1:00
Canadian Summer time runs from 3 April 0:00 to 30 October 0:00Parameters
In the northern hemisphere the EndDate > StartDate. In the southern hemisphere, summertime crosses the new year, so EndDate < StartDate. For this reason if you want to check if your current date is in summer time, you must simply check the relative order of StartDate and EndDate.
Will Bateman (Nov 2004)
FUNCTION
summerTime
Calculates if the provided date occurs in summer time. You might use the result from this function to add 1 hour to nDate in order to factor in Summer time variations. Summer time is always applied some time between midnight (12am) and 3am, with this time being repeated twice during the transition from summer to winter time. To capture the transition correctly, it is important that nDate represents local time without summer time, such that the addition of 1hr is only added to during the summer. For example:
if(summerTime(somedate, st_UK)) somedate+=1/24.0;N.B. You should not subtract 1hr from a summer time value in order to obtain standard time for the winter months, as this will yield slightly incorrect times at the transition from winter to summer (the changeover occurring 1 hour early).
Example 1
#include <stdio.h>
#include <codecogs/units/time/summertime.h>
#include <codecogs/units/date/day.h>
#include <codecogs/units/time/hour.h>
#include <codecogs/units/time/minute.h>
void main()
{
double nDate=date("30 oct 2004");
for(double i=22/24.0;i<26/24.0;i+=1/48.0)
{
double a=nDate+i;
bool summer=summerTime(a, st_UK);
a+=summer* 1/24.0;
printf("\n %s day=%d time=%2d:%02d", summer?"Summer":"Winter", day(int(a)), hour(a), minute(a));
}
}Output:
Summer day=30 time=23:00
Summer day=30 time=23:30
Summer day=31 time= 0:00
Summer day=31 time= 0:30
Summer day=31 time= 1:00
Summer day=31 time= 1:30
Winter day=31 time= 1:00
Winter day=31 time= 1:30
Winter day=31 time= 2:00Parameters
Will Bateman (Nov 2004)