?
Solved

Parsing time zone database

Posted on 2013-10-30
10
Medium Priority
?
876 Views
Last Modified: 2013-11-11
We have time zone objects in our code that we fill from a time zone file that we maintain manually. This is silly because there is a nice one (Olson's) that already exists on Linux and in glibc so it should be readily available to our compiler.

What I'm trying to do is parse through the time zone database to fill our time zone structures. I'm having trouble figuring out the best way to do this. I don't really want to parse the entire file and match all the current rules to the current time zone definitions etc. I only care about the current rules. I assume there is a better way to do this than starting from scratch with the tz database text files. I'm trying to produce something like this for all of them:
Zone name        offset DST? dst_mo   dst_day  dst_hr  std_mo std_day std_hr
UTC                0:00    0
America/New_York  -5:00    1      3    Sun>=8       2      11  Sun>=1      2
Europe/Paris      +1:00    1      3   lastSun       1      10 lastSun      1

Open in new window

Isn't there some good way to call into time.h or something to get this? I can't seem to find one.
0
Comment
Question by:TommySzalapski
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 14

Expert Comment

by:frankhelk
ID: 39620192
I havn't seen the original files, but it can't be that complicated to parse them.
Could you attach one of these files ?

Other idea: Maybe there's something useful in the TimeZoneInfo class (MS C#/C++) ?
0
 
LVL 37

Author Comment

by:TommySzalapski
ID: 39621769
I don't need to attach them, they are publicly available and already on your computer (even in you use MS which it appears you do, although I think they hide it somewhat).
IANA officially maintains them.
http://www.iana.org/time-zones

I use Linux (note the zones) so MS and C# don't really help.

Again. I certainly could write a parser for the files, but since they are built into GCC, surely there is a better way.
0
 
LVL 14

Expert Comment

by:frankhelk
ID: 39623700
Ooops - mybe I was not fully awake when reading the question. Sorry.

Have you checked out the ressouce links there ?

http://www.iana.org/time-zones/repository/tz-link.html

I've just read over them, but it looks like there's some useful code there ...
0
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
LVL 37

Author Comment

by:TommySzalapski
ID: 39624245
But if all of that data is already built into glibc, then why should I be reinventing the wheel and writing a parser for a flat text file?
0
 
LVL 14

Expert Comment

by:frankhelk
ID: 39624526
OK - I reverse my thought about parsing ... just use the already invented wheel and utilize the routines/classes in glibc (I've not looked over those routines, but I bet they're an equal replacement for the C#/VC classes I've mentioned while being on the Windows rail ...).

While thinking abut, how about that: The files from the IANA site (the TZ database) contains a makfile to generate binary tz files, which I presume glibc reads.

How about just adding creating some kind of addendum with your own time zone to one of the original tz files and appending it to the dl'd file automatically when new IANA files are available. When you subsequently compile the files with the IANA makefile to get the binary tz files, there should not be much in the way to use them and have your own tz available with the glibc stuff ?
0
 
LVL 37

Author Comment

by:TommySzalapski
ID: 39625859
Hmm... still not quite awake yet? :)
I'm not trying to add new timezones, I'm trying to get the ones that are already in glibc and put them into our structures.

Anyway, I tried to find what I needed in time.h and other files but had no success.
I suppose I could parse the binary files which would be a bit easier, but I'd prefer library calls.
0
 
LVL 14

Assisted Solution

by:frankhelk
frankhelk earned 1000 total points
ID: 39628309
Hmmm ... OK. Weird thing, that brain of mine.

Nevertheless, I've browsed a bit thru http://www.gnu.org/software/libc/manual/pdf/libc.pdf

Seems it deals with timezones here and there, and it's possibly more informative than time.h ... but I presume you've read that, too ...

Just a tought - while glibc incorporates  the info of the IANA files, their data needs to be included into the sources of glibc in some way. Maybe a peek into these sources might lead to some kind of back door to that data, or you could possibly insert a custom extension into that code somewhere to achive that goal ?
0
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 0 total points
ID: 39628404
You are correct. I already read the info in the pdf and there's nothing particularly useful.
Peeking into the glibc code isn't a bad idea, I'm guessing they get the data from where I just found it.
I've done some searching and here is what I've found so far.

There are binary files (super easy to 'parse') stored here: /usr/share/zoneinfo
You can get the most recent text files here: http://www.iana.org/time-zones
And compile them into the binary format using zic on the command line (time zone compiler that ships with Linux).

I think we'll end up going that route. I do appreciate your time trying to help me figure this out.
0
 
LVL 37

Author Comment

by:TommySzalapski
ID: 39628414
The IANA also publishes a library that you can link with to get the data. I haven't really messed with it, but you can get to it here: http://www.iana.org/time-zones
0
 
LVL 37

Author Closing Comment

by:TommySzalapski
ID: 39638304
I think I found the best solution for my needs. As a side note, boost's timezone stuff is a bit more fleshed out than the time.h stuff. Anyone reading this in the future might want to look there: http://www.boost.org/doc/libs/1_54_0/doc/html/date_time.html
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question