<<< Back to the Linux Tips Index

29th October 2023

Daylight Savings Time

dst

Daylight Savings Time and Log Files

Please note that this article is only discussing how DST affects log files. DST affects all manner of things - the amount of time between a transaction in Sydney, Australia and how it was recorded in Dusseldorf, Germany involves a lot of incredibly complicated calculations, most of which are politically affected more than technical considerations. This article is a simplification of that more general issue with timezones and DST.

Most countries have Daylight Savings Time (DST); some larger countries even have different DST rules within the same country. This is great for various reasons, ensuring that people are active during daylight hours, reducing vehicle collisions caused by driving in dark conditions, and many other factors too.

For simplicity, this article is deliberately written with an emphasis on the UK (Northern Hemisphere) experience of DST, where DST is fairly simple. For many locations, it is far less simple, which makes this post actually more relevant. The UK is a fairly simple scenario; others have far more complex situations, and local governments can change the rules on a whim - and sometimes do so, at short notice.

DST (in the Northern Hemisphere) works on the basis of "Spring Forward, Fall Back" - that is, in the spring time, we bounce ahead into a "summer time", where we do everything an hour ahead of what we would otherwise do, and in Fall (or Autumn), we fall back to the regular time zone.

In the UK, we put the clock forward by one hour every Spring, and put it back by one hour every Autumn. So this is a nice and simple case.

Here is a very simple shell script which logs events as they happen:

Here is how they are logged:

We can see that the event sequences are invalidated as the operating system moves the clock back - two minutes after 01:59:12 we get to 01:01:12.

It seems that Event #8 happened before Event #7.

So if an event happened at 01:39:17, would we know if that event happened before Event #1 or after Event #10?

Our logs become meaningless in terms of our ability to understand what happened within that hour-long space.

And what if somebody from France, Uzbekistan, Georgia (which one?!), China (which timezone) or anybody else wanted to check what happened when - how would you answer them?!

UTC To The Rescue

UTC is the Coordinated Universal Time. If you log your data in UTC, you can deal with these changes, by simply ignoring them. You have a single, coherent, centrally-agreed time, and local DST values can be reflected by the various changing rules which affect the local timezones, without messing with your logfiles or anything else.

Many programming languages, such as Java, have built-in capabilities to allow for these changes between timezones, although these do depend upon their underlying configurations being kept up-to-date as different local governments change their preferences on daylight-savings times.

 

Invest in your career. Buy my Shell Scripting Tutorial today:

Shell Scripting Tutorial

 

steve-parker.org
Share on Twitter Share on Facebook Share on LinkedIn Share on Identi.ca Share on StumbleUpon