DayLight Saving Code

Catalog of dial plans
Post Reply
mnipp
Posts: 192
Joined: Sat Oct 03, 2009 9:48 am
Location: NSW Australia

DayLight Saving Code

Post by mnipp » Sun Mar 28, 2010 3:29 am

I added some code that corrects for daylight saving time, but because it was best the code works for every year even if the dates are not updated. A slightly different approach was needed for the Southern Hemisphere where DayLightSaving includes the new year.

Code: Select all

# Northern Hemisphere Daylight Saving code (London example)

tz = 0                 # Time zone (GMT+0)London time Zone
 t = Time.now.utc + (tz*60*60)

 # day  month in MMDD form. example march/6 = 0306
 dstimeStartday = "0328"   # Start of London SummerTime   March/28 2010
 dstimeEndday   = "1031"   #  End  of London SummerTime October/31 2010
 if (dstimeStartday...dstimeEndday) === t.strftime("%m%d") # Check if todays date is in DST Date range.
     t = Time.now.utc + ((tz+1)*60*60)                    # if true add 1 hour to tz TimeZone.
 end
  logtime = t.strftime("%A(%w) (%H%M)%I:%M%p %Y(%m%d)") # Check Day Time and Date in Console output.
  sys.log("#{logtime}")

Code: Select all

# Southern Hemisphere Daylight Saving code (Australian example)

tz = +10                 # Time zone (GMT+10 hours)Sydney AEST time Zone
 t = Time.now.utc + (tz*60*60)

 # day  month in MMDD form. example march/6 (0306)
 dstimeStartday = "1003"   # Start of Sydney DaylightSavingTime October/03 2010
 dstimeEndday   = "0403"   #  End  of Sydney DaylightSavingTime  April/03  2011
 if !( (dstimeEndday...dstimeStartday) === t.strftime("%m%d") ) # Check if todays date is outside DST Date range.
     t = Time.now.utc + ((tz+1)*60*60)                         # if false add 1 hour to tz TimeZone.
 end
  logtime = t.strftime("%A(%w) (%H%M)%I:%M%p %Y(%m%d)") # Check Day Time and Date in Console output.
  sys.log("#{logtime}")
billion 7404VGP
dialplan (<9*:*>[0-9*][0-9*].T<:@sipbroker>|[0-9*].T)

Post Reply