An article to document how I calculated the start and end dates of when Daylight Savings Time is in effect.
Why?
Admittedly, most of Zoho apps have this built-in but here's some snippets of code in case you need them.
How?
I will use this to amend and refine but here's the snippets for the various DSTs around the world.
US (Except Arizona, Hawaii and US Territories?):
- DST Start Starts Second Sunday in March at 2:00
- DST End Ends First Sunday in November at 2:00
// // Starts Second Sunday in March at 2:00 v_FirstMonthDate = toTime(zoho.currentdate.toString("yyyy") + "-03-08 02:00:00"); // // Ends First Sunday in November at 2:00 v_LastMonthDate = toTime(zoho.currentdate.toString("yyyy") + "-11-01 02:00:00"); // // loop through each day in a week to get the start and end dates for each v_DayIndex in {0,1,2,3,4,5,6} { v_CheckDateStart = v_FirstMonthDate.addDay(v_DayIndex); if(v_CheckDateStart.toString("E")=="Sun") { v_DST_StartTime = v_CheckDateStart; } v_CheckDateEnd = v_LastMonthDate.addDay(v_DayIndex); if(v_CheckDateEnd.toString("E")=="Sun") { v_DST_EndTime = v_CheckDateEnd; } } info "Start Date (Current Year): " + v_DST_StartTime.toString("EEEE, yyyy-MM-dd HH:mm"); info "End Date (Current Year): " + v_DST_EndTime.toString("EEEE, yyyy-MM-dd HH:mm"); // // Starts Second Sunday in March at 2:00 v_FirstMonthDate = toTime(zoho.currentdate.addYear(1).toString("yyyy") + "-03-08 02:00:00"); // // Ends First Sunday in November at 2:00 v_LastMonthDate = toTime(zoho.currentdate.addYear(1).toString("yyyy") + "-11-01 02:00:00"); // // loop through each day in a week to get the start and end dates for each v_DayIndex in {0,1,2,3,4,5,6} { v_CheckDateStart = v_FirstMonthDate.addDay(v_DayIndex); if(v_CheckDateStart.toString("E")=="Sun") { v_DST_StartTime = v_CheckDateStart; } v_CheckDateEnd = v_LastMonthDate.addDay(v_DayIndex); if(v_CheckDateEnd.toString("E")=="Sun") { v_DST_EndTime = v_CheckDateEnd; } } info "Start Date (Next Year): " + v_DST_StartTime.toString("EEEE, yyyy-MM-dd HH:mm"); info "End Date (Next Year): " + v_DST_EndTime.toString("EEEE, yyyy-MM-dd HH:mm");
- //
- // Starts Second Sunday in March at 2:00
- v_FirstMonthDate = toTime(zoho.currentdate.toString("yyyy") + "-03-08 02:00:00");
- //
- // Ends First Sunday in November at 2:00
- v_LastMonthDate = toTime(zoho.currentdate.toString("yyyy") + "-11-01 02:00:00");
- //
- // loop through each day in a week to get the start and end dates
- for each v_DayIndex in {0,1,2,3,4,5,6}
- {
- v_CheckDateStart = v_FirstMonthDate.addDay(v_DayIndex);
- if(v_CheckDateStart.toString("E")=="Sun")
- {
- v_DST_StartTime = v_CheckDateStart;
- }
- v_CheckDateEnd = v_LastMonthDate.addDay(v_DayIndex);
- if(v_CheckDateEnd.toString("E")=="Sun")
- {
- v_DST_EndTime = v_CheckDateEnd;
- }
- }
- info "Start Date (Current Year): " + v_DST_StartTime.toString("EEEE, yyyy-MM-dd HH:mm");
- info "End Date (Current Year): " + v_DST_EndTime.toString("EEEE, yyyy-MM-dd HH:mm");
- //
- // Starts Second Sunday in March at 2:00
- v_FirstMonthDate = toTime(zoho.currentdate.addYear(1).toString("yyyy") + "-03-08 02:00:00");
- //
- // Ends First Sunday in November at 2:00
- v_LastMonthDate = toTime(zoho.currentdate.addYear(1).toString("yyyy") + "-11-01 02:00:00");
- //
- // loop through each day in a week to get the start and end dates
- for each v_DayIndex in {0,1,2,3,4,5,6}
- {
- v_CheckDateStart = v_FirstMonthDate.addDay(v_DayIndex);
- if(v_CheckDateStart.toString("E")=="Sun")
- {
- v_DST_StartTime = v_CheckDateStart;
- }
- v_CheckDateEnd = v_LastMonthDate.addDay(v_DayIndex);
- if(v_CheckDateEnd.toString("E")=="Sun")
- {
- v_DST_EndTime = v_CheckDateEnd;
- }
- }
- info "Start Date (Next Year): " + v_DST_StartTime.toString("EEEE, yyyy-MM-dd HH:mm");
- info "End Date (Next Year): " + v_DST_EndTime.toString("EEEE, yyyy-MM-dd HH:mm");
Start Date (Current Year): Sunday, 2021-03-14 02:00 End Date (Current Year): Sunday, 2021-11-07 02:00 Start Date (Next Year): Sunday, 2022-03-13 02:00 End Date (Next Year): Sunday, 2022-11-06 02:00
- Start Date (Current Year): Sunday, 2021-03-14 02:00
- End Date (Current Year): Sunday, 2021-11-07 02:00
- Start Date (Next Year): Sunday, 2022-03-13 02:00
- End Date (Next Year): Sunday, 2022-11-06 02:00
Europe:
- DST Start Last Sunday in March at 1:00 UTC
- DST End Last Sunday in October at 1:00 UTC
// // Starts Last Sunday in March at 1:00 UTC v_FromMonthDate1 = toTime(zoho.currentdate.toString("yyyy") + "-04-01 01:00:00"); // // Ends Last Sunday in October at 1:00 UTC v_ToMonthDate1 = toTime(zoho.currentdate.toString("yyyy") + "-10-31 01:00:00"); // // loop through each day in a week to get the start and end dates for each v_DayIndex in {0,1,2,3,4,5,6} { v_CheckDateStart = v_FromMonthDate1.subDay(v_DayIndex); if(v_CheckDateStart.toString("E")=="Sun") { v_DST_StartTime = v_CheckDateStart; } v_CheckDateEnd = v_ToMonthDate1.subDay(v_DayIndex); if(v_CheckDateEnd.toString("E")=="Sun") { v_DST_EndTime = v_CheckDateEnd; } } // // output info "Start Date (Current Year): " + v_DST_StartTime.toString("EEEE, yyyy-MM-dd HH:mm"); info "End Date (Current Year): " + v_DST_EndTime.toString("EEEE, yyyy-MM-dd HH:mm"); // // ********************************************************* // // Starts Last Sunday in March at 1:00 UTC v_FromMonthDate1 = toTime(zoho.currentdate.addYear(1).toString("yyyy") + "-04-01 01:00:00"); // // Ends Last Sunday in October at 1:00 UTC v_ToMonthDate1 = toTime(zoho.currentdate.addYear(1).toString("yyyy") + "-10-31 01:00:00"); // // loop through each day in a week to get the start and end dates for each v_DayIndex in {0,1,2,3,4,5,6} { v_CheckDateStart = v_FromMonthDate1.subDay(v_DayIndex); if(v_CheckDateStart.toString("E")=="Sun") { v_DST_StartTime = v_CheckDateStart; } v_CheckDateEnd = v_ToMonthDate1.subDay(v_DayIndex); if(v_CheckDateEnd.toString("E")=="Sun") { v_DST_EndTime = v_CheckDateEnd; } } info "Start Date (Next Year): " + v_DST_StartTime.toString("EEEE, yyyy-MM-dd HH:mm"); info "End Date (Next Year): " + v_DST_EndTime.toString("EEEE, yyyy-MM-dd HH:mm");
- //
- // Starts Last Sunday in March at 1:00 UTC
- v_FromMonthDate1 = toTime(zoho.currentdate.toString("yyyy") + "-04-01 01:00:00");
- //
- // Ends Last Sunday in October at 1:00 UTC
- v_ToMonthDate1 = toTime(zoho.currentdate.toString("yyyy") + "-10-31 01:00:00");
- //
- // loop through each day in a week to get the start and end dates
- for each v_DayIndex in {0,1,2,3,4,5,6}
- {
- v_CheckDateStart = v_FromMonthDate1.subDay(v_DayIndex);
- if(v_CheckDateStart.toString("E")=="Sun")
- {
- v_DST_StartTime = v_CheckDateStart;
- }
- v_CheckDateEnd = v_ToMonthDate1.subDay(v_DayIndex);
- if(v_CheckDateEnd.toString("E")=="Sun")
- {
- v_DST_EndTime = v_CheckDateEnd;
- }
- }
- //
- // output
- info "Start Date (Current Year): " + v_DST_StartTime.toString("EEEE, yyyy-MM-dd HH:mm");
- info "End Date (Current Year): " + v_DST_EndTime.toString("EEEE, yyyy-MM-dd HH:mm");
- //
- // *********************************************************
- //
- // Starts Last Sunday in March at 1:00 UTC
- v_FromMonthDate1 = toTime(zoho.currentdate.addYear(1).toString("yyyy") + "-04-01 01:00:00");
- //
- // Ends Last Sunday in October at 1:00 UTC
- v_ToMonthDate1 = toTime(zoho.currentdate.addYear(1).toString("yyyy") + "-10-31 01:00:00");
- //
- // loop through each day in a week to get the start and end dates
- for each v_DayIndex in {0,1,2,3,4,5,6}
- {
- v_CheckDateStart = v_FromMonthDate1.subDay(v_DayIndex);
- if(v_CheckDateStart.toString("E")=="Sun")
- {
- v_DST_StartTime = v_CheckDateStart;
- }
- v_CheckDateEnd = v_ToMonthDate1.subDay(v_DayIndex);
- if(v_CheckDateEnd.toString("E")=="Sun")
- {
- v_DST_EndTime = v_CheckDateEnd;
- }
- }
- info "Start Date (Next Year): " + v_DST_StartTime.toString("EEEE, yyyy-MM-dd HH:mm");
- info "End Date (Next Year): " + v_DST_EndTime.toString("EEEE, yyyy-MM-dd HH:mm");
Start Date (Current Year): Sunday, 2021-03-28 01:00 End Date (Current Year): Sunday, 2021-10-31 01:00 Start Date (Next Year): Sunday, 2022-03-27 01:00 End Date (Next Year): Sunday, 2022-10-30 01:00
- Start Date (Current Year): Sunday, 2021-03-28 01:00
- End Date (Current Year): Sunday, 2021-10-31 01:00
- Start Date (Next Year): Sunday, 2022-03-27 01:00
- End Date (Next Year): Sunday, 2022-10-30 01:00
Additional Note(s):
- This has not been tested extensively. Do not use if you are unsure it is calculating correctly. I use these to store the values in a table that can be double-checked at a later date.
Source(s):
- Joel Lipman: Zoho Deluge: Generate List of TimeZones
- Joel Lipman DataSources: Time zones supported by Zoho (MS Excel file)
- Wikipedia: Daylight saving time by country
- Wikipedia: List of tz database time zones