Steve on Image Processing with MATLAB

Image processing concepts, algorithms, and MATLAB


Steve on Image Processing with MATLAB has been archived and will not be updated.

Time zone terminology

An email thread about a date-related design question had me thinking about terminology this week. (Note: There's nothing about image processing in today's post. Sorry!)

Specifically, I was thinking about the term time zone. In the U.S. you might see a date written this way:

November 21, 2004 1:02 PM (EST)

EST means Eastern Standard Time in the U.S. Or you might see a date written like this:

11/21/2004 8:30 (-04:00)

Many people refer to EST or -04:00 as the "time zone." However, because I work across the hall from the chief designer and implementer (Hi, P^2) of the new datetime suite of functions in MATLAB R2014b, I know that these are more properly referred to as time zone offsets.

A time zone is a much more complex concept than a simple offset from UTC. For example, a time zone encompasses both current and historical rules for using Daylight Saving Time.

The time zone offset for a given time depends not only on the time zone but also both the year and the day-of-year.

The dependence on the day-of-year is pretty obvious. In the fall season where I live, the time zone offset depends on whether the day is before or after the first Sunday in November.

d1 = datetime('October 15, 2014','TimeZone','America/New_York')
d1 = 


ans = 


d2 = datetime('November 15, 2014','TimeZone','America/New_York')
d2 = 


ans = 


Most of the state of Arizona does not observe Daylight Saving Time.

d3 = datetime('October 15, 2014','TimeZone','America/Phoenix')
d3 = 


ans = 


d4 = datetime('November 15, 2014','TimeZone','America/Phoenix')
d4 = 


ans = 


The dependence of time zone offset on the year is somewhat less obvious. It turns out that Daylight Saving Time rules change occasionally. In the U.S. the rules were last changed in 2007. Let's compare the time zone offset for noon on Halloween for 2007 and 2006.

d5 = datetime('October 31, 2007 12:00 PM','TimeZone','America/New_York')
d5 = 

   31-Oct-2007 12:00:00

ans = 


d6 = datetime('October 31, 2006 12:00 PM','TimeZone','America/New_York')
d6 = 

   31-Oct-2006 12:00:00

ans = 


Now for just a little fun with MATLAB R2014b date calculations. Most of the U.S. changes from Daylight Saving time to Standard Time at 2:00 AM on the first Sunday of November. Given the year, how can we compute that?

Here's just one way. Start with 2:00 AM on November 1 of the specified year.

year = 2014;
d = datetime(year,11,1,2,0,0)
d = 

   01-Nov-2014 02:00:00

Now use dateshift to move to the first Sunday.

dateshift(d,'dayofweek','Sunday')  % You can also use 1 instead of 'Sunday'.
ans = 

   02-Nov-2014 02:00:00

My horoscope for today said "Your next blog will include an example of an anonymous function for no good reason." So here it is. Let's make an anonymous function that returns the exact time for the transition from Daylight Saving Time to Standard time in the U.S.

f = @(year) dateshift(datetime(year,11,1,2,0,0),'dayofweek','Sunday')
f = 


ans = 

   02-Nov-2014 02:00:00

ans = 

   01-Nov-2015 02:00:00

ans = 

   06-Nov-2016 02:00:00

Of course, this function only works for years between 2007 and whenever the U.S. Congress changes its mind again!

Next week, I promise, I'll get back to writing about image processing. Or maybe colormaps. Unless I write about something else.

Published with MATLAB® R2014b

  • print


To leave a comment, please click here to sign in to your MathWorks Account or create a new one.