5 ms·
Oh this reawakens painful memories dealing with timezones and dates! :( The shock horror is that there isn't any standard C API nor library for dealing with ti
by willvarfar 10y ago
Oh this reawakens painful memories dealing with timezones and dates! :(
The shock horror is that there isn't any standard C API nor library for dealing with time zones properly.
`localtime()` will convert a time to your current timezone. You can find code that tries to work around this by acquiring locks and setting environment variables before each invocation of `localtime`.
There is no API that lets you specify another timezone (except, perhaps, NetBSD which has a `localtime_rz` function).
There is also no good way of getting a definitive list of work days and non-work-days for countries in the world.
When working on a system fairly recently that had to avoid doing something on evenings, weekends and non-working-days in France, I ended up parsing the 'secret, can be changed at any time' tzinfo files directly and compiling my own list of holiday days in France. And then there was a horrid terrorist attack and three days of national mourning in France and my code didn't realise and that was an awful feeling.
- susam 10y agoI once had to spend an entire evening finding the root cause of a bug in a time parsing code I used to work on that would show up only when DST is in effect. The bug was due to the way mktime() function used the value of tm_isdst member variable of struct tm. If DST was in effect and t->tm_isdst = 0, then mktime(t) would add an hour to t and set t->tm_isdst = 1. If DST was not in effect and t->tm_isdst = 1, then mktime(t) would subtract an hour from t and set t->tm_isdst = 0. See http://stackoverflow.com/q/9041514/303363 http://stackoverflow.com/q/9041514/303363 for more details.
- viraptor 10y agoAs I read the post, I was thinking - that won't help the situation when royalty in the UK has a baby and announces a new holiday. Well... now I have two examples why the definitive list is impossible.
- willvarfar 10y agoThe timezone DB is centrally maintained by the IANA, and changes happen several times a year. Most OS automatically update it over their packaging system. Its a shame it isn't extended to include national holidays and such, and that UNIX standardizes (and platforms adopt) an API for working with timezones correctly. As the IANA now manage the timezone DB, it could put the onerous on publishing and updating such a DB on each country's delegate. Even North Korea cooperates with the IANA!
- masklinn 10y ago> Its a shame it isn't extended to include national holidays and such Yes because if there's one thing I'd want to deal with it's wandering religious holidays (hello easter), religious holidays for only a subset of some local population (e.g. different holidays for muslims and hindu), regional holidays, company-specific holidays, government holidays which companies may or may not want (or have) to follow, etc… Not to mention holiday doesn't necessarily mean the people following it don't work, so what would you even do with that information?
- manigandham 10y ago> national holidays These are too subjective, localized and of differing "seriousness" to be worth it. Timezones are actually objective and valuable information that should be standardized.
- willvarfar 10y agoWe have differing levels for "worth it" clearly :) Having had to work with requirements like "send pager alerts if outside normal business hours in the UK", where UK has a standard government-controlled definition of normal business hours and a government-controlled definition of whether Easter or a "bank holiday" is a business day etc, well, my life would be greatly simplified if it wasn't required that I personally collate and maintain a diary for each country...
- imglorp 10y agoOh boy. Every time some nitwit government decides to screw with its dst (after they get done trying to set pi to 3), it's a cascading exit wound costing millions downstream. First the OS vendor needs to scramble to get the new TZ database incorporated. This might or might not entail a lawsuit[1]. Next, the ISV's and OEM's scramble to update the OS in their offering. If you're talking life and safety equipment, validating a new OS might be expensive and painful, especially if it screws with localtime() and all those subtle bugs. Next the field hardware has to get updated. All that embedded stuff at customer sites? Yeah. Another upgrade. Localtime, just say no! 1. http://www.techrepublic.com/blog/australian-technology/time-zone-database-lawsuit-dismissed/ http://www.techrepublic.com/blog/australian-technology/time-...
- astrodust 10y agoZulu for everyone?
- masklinn 10y agoPeople will still want and need a concept of local time, so you'll end up with pretty much the same thing, possibly better, possibly worse, but not markedly different.
- astrodust 10y agoPeople don't need a local time, they expect one based on tradition. If we all agreed that Zulu or Stardate or whatever was the way to go, and we had a singular planetary time, we'd all know what that time meant in local terms. Maybe your sun rises at 00:12 and mine at 08:15. Maybe you go to work at 01:00 and we do at 10:00. Local traditions prevail. Unfortunately establishing a world-wide time system would probably have people screaming something about the Illuminati, the New World Order or Reptilians. This is why we can't have nice things.
- masklinn 10y ago> People don't need a local time People do need a local time. > Maybe your sun rises at 00:12 and mine at 08:15. That's already the case regardless of timezones (sunrise is currently at 02:24 in Akureyri, Iceland with sunset at 00:10) > Maybe you go to work at 01:00 and we do at 10:00. When shops open or close, people take dinner, the trains start and stop running or people go to work are all local time concepts. If you don't provide convenient time notations for local times people will just make their own because they need to talk about these concepts and synchronise based on them anyway. That has nothing to do with local traditions, it's a form of compression. > This is why we can't have nice things. UTC already exists, and foisting it on everybody regardless of their actual needs is not a nice thing, it's just technologist laziness.