In this, the sixth course in the series, we take a look at a concept that cannot be ignored when an application goes beyond the borders of a single country: time zones.
As soon as it becomes necessary to display a date or time in the user’s time zone, time management quickly becomes complex. Time shifts, reference cities, summer and winter time, ISO 8601 formats with offset… all subjects that seem simple at first glance, but require a real method to be handled properly.
In this course, we’ll enhance our Stmp class to enable it to load and use a complete time zone repository, associate cities with their zones, calculate offsets between cities, and then adapt the fundamental functions of the class (build, now, getDate, getTime) so that they can integrate this international dimension.
We’ll also look at how ISO 8601 conversion functions can be upgraded to explicitly manage time offsets, and thus produce or interpret dates and times in standardized formats that can be used in exchanges between systems.
Beyond the time zones themselves, this course is also a very good illustration of several good design practices: deferred resource loading, data caching, management of shared properties in a singleton, progressive evolution of an existing API, and use of variadic parameters to keep the interface both flexible and powerful.