Is there a PB implementation for the Olson Timezone DB before I write one?
Announcement
Collapse
No announcement yet.
Olson Timezone DB
Collapse
X
-
Heck I could not find anything but a .NET API.
I guess you get to do it yourself. But on the plus side....it should not be too hard...
File formats
The zoneinfo database is published as a set of text files which list the rules and zone transitions in a human-readable format. For use, these text files are compiled into a set of platform-independent binary files—one per time zone. The reference source code includes such a compiler called zic (zone information compiler), as well as code to read those files and use them in standard APIs such as localtime() and mktime().
... er, at least the part where you start with the human-readable format should not be too hard.
I'll guess the current compiled binary files use some kind of compression and the APIs decompress on the fly as needed.
There's a number of folks here who have 'big interest' in compression technology... you should be able to find a couple of relevant threads here to get you started.
MCMMichael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
-
Olson Timezone DB
I ran google for an hour and couldn't uncover anything related to various BASIC language flavors that I could co-opt. This is my first effort in using PB and have a date/time DLL with all kinds of goodies in it - only missing timezone support. I plan on uploading the source here when I'm done and move on to my first "real" project after this familiarization effort.
The Olson files look pretty straightforward.
1. Skip lines that start with '#'
2. Skip blank lines
3. Change all the tab chars to spaces
4. Compress two consecutive spaces until no more occurences are found
5. Split the line into an array
6. Remove possible trailing comments by looking for a '#' character
7. First array entry will tell you what to do
or something along similiar lines.
So now, the only question is the format for the output side. I could emit a series of DATA statements for a DLL one could compile that loaded some arrays, SQLlite, custom external file, etc and then exposed some functions for TZ retrievals of various sorts.
More thought obviously needed....
Rick------------------------------------------------------------
sigpic
It has come to my attention that certain dubious forces are interpolating their desires in my search for Mom, apple pie and the girl you left behind. Stop it or I'll scream...
Comment
-
This is my first effort in using PB and have a date/time DLL with all kinds of goodies in it - only missing timezone supportMichael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
Olson Timezone DB
I'm kind of a nut with regard to dates and times. The PB DLL I have now exposes about 45 functions and supports Gregorian, Chinese (with Korean, Vietnamese, Japanese sub variants), ISO, Julian, Hebrew, Islamic (observational), Persian, Hindu Solar and Lunar, etc calendars. Moonrise/set, Sunrise/set, Bearing, Distance, Lunar Illumination, Rules based calculation of Gregorian dates, Business date calcuations, Weekday, various types of date/time math, retrieval of TZInfo from Windows with option of getting the actual transition date/times, and a fistful of misc stuff that I just found interesting. I just want the ability to move a date/time from one timezone to another and the Olson db seems the best source for all the rules that have occurred. Windows API's are good for local to UTC and UTC to local and that's about all I want from the OS.
It's all good learning and fun to boot....
Rick------------------------------------------------------------
sigpic
It has come to my attention that certain dubious forces are interpolating their desires in my search for Mom, apple pie and the girl you left behind. Stop it or I'll scream...
Comment
-
One way the code might look for those rules, tho I never saw any actual data, so I just made an example line:
Code:#COMPILE EXE #DIM ALL FUNCTION PBMAIN () AS LONG '1. Skip lines that start with '#' '2. Skip blank lines '3. Change all the tab chars to spaces '4. Compress two consecutive spaces until no more occurences are found '5. Split the line into an array '6. Remove possible trailing comments by looking for a '#' character '7. First array entry will tell you what to do LOCAL x AS LONG, lineOdata AS STRING ' OPEN file FOR INPUT AS #1 ' LINE INPUT lineOdata lineOdata = "123456 asdfgh 123456 123456 asdfgh" & $TAB & $TAB & $TAB & "123456 asdfgh 123456 asdfgh" ? "An example data line: " & $CRLF & $CRLF & lineOdata IF ASC(lineOdata, 1) <> 35 THEN 'if 1st char not = "#" IF lineOdata > " " THEN 'and line isn't blank REPLACE ANY $TAB WITH $SPC IN lineOdata 'tabs change to spaces DO IF INSTR(lineOdata, " ") THEN '2 spaces change to one space until none left REPLACE " " WITH $SPC IN lineOdata' " " " ELSE EXIT DO END IF LOOP x = PARSECOUNT(lineOdata, $SPC) 'split to array DIM timeZonArr(1 TO x) AS STRING ' " PARSE lineOdata, timeZonArr(), $SPC ' " ? timeZonArr(1) '1st element ? timeZonArr(5) '5th element END IF END IF END FUNCTION
Comment
-
I just want the ability to move a date/time from one timezone to another and the Olson db seems the best source for all the rules that have occurred. Windows API's are good for local to UTC and UTC to local and that's about all I want from the OS.
OTOH, if your real challenge is "what is the timezone adjustment between New York and Bangkok - today" that's where AFAIK you'll need some kind of non-intrinsic support such as the Olsen DB.Michael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
Originally posted by Michael Mattias View PostUTC is universal. If you know the source and destination timezones the WInAPI can get you the local times.
OTOH, if your real challenge is "what is the timezone adjustment between New York and Bangkok - today" that's where AFAIK you'll need some kind of non-intrinsic support such as the Olsen DB.
Even in it's current form, perhaps if I upload the work so far, it might assist you and others to get a idea of what I'm up to.
Rick------------------------------------------------------------
sigpic
It has come to my attention that certain dubious forces are interpolating their desires in my search for Mom, apple pie and the girl you left behind. Stop it or I'll scream...
Comment
-
Originally posted by Marc Giao View PostHi Rick,
I think you and our other PowerBASIC time lord and date guru, Egbert Zijlema, have a lot to talk about:
I am surprised he hasn't said hello yet
That would be interesting!I'm the former date guru for Corel Paradox (http:\\www.thedbcommunity.com)
------------------------------------------------------------
sigpic
It has come to my attention that certain dubious forces are interpolating their desires in my search for Mom, apple pie and the girl you left behind. Stop it or I'll scream...
Comment
-
Originally posted by John Gleason View PostOne way the code might look for those rules, tho I never saw any actual data, so I just made an example line:
Code:#COMPILE EXE #DIM ALL FUNCTION PBMAIN () AS LONG '1. Skip lines that start with '#' '2. Skip blank lines '3. Change all the tab chars to spaces '4. Compress two consecutive spaces until no more occurences are found '5. Split the line into an array '6. Remove possible trailing comments by looking for a '#' character '7. First array entry will tell you what to do LOCAL x AS LONG, lineOdata AS STRING ' OPEN file FOR INPUT AS #1 ' LINE INPUT lineOdata lineOdata = "123456 asdfgh 123456 123456 asdfgh" & $TAB & $TAB & $TAB & "123456 asdfgh 123456 asdfgh" ? "An example data line: " & $CRLF & $CRLF & lineOdata IF ASC(lineOdata, 1) <> 35 THEN 'if 1st char not = "#" IF lineOdata > " " THEN 'and line isn't blank REPLACE ANY $TAB WITH $SPC IN lineOdata 'tabs change to spaces DO IF INSTR(lineOdata, " ") THEN '2 spaces change to one space until none left REPLACE " " WITH $SPC IN lineOdata' " " " ELSE EXIT DO END IF LOOP x = PARSECOUNT(lineOdata, $SPC) 'split to array DIM timeZonArr(1 TO x) AS STRING ' " PARSE lineOdata, timeZonArr(), $SPC ' " ? timeZonArr(1) '1st element ? timeZonArr(5) '5th element END IF END IF END FUNCTION
Code:#COMPILE EXE #DIM ALL #DEBUG DISPLAY ON FUNCTION PBMAIN () AS LONG LOCAL dwIndex AS LONG LOCAL dwCount AS LONG LOCAL dwTrailer AS LONG LOCAL sOlsonTimeZone AS STRING LOCAL arOlson() AS STRING LOCAL iFile AS INTEGER LOCAL oFile AS INTEGER LOCAL quFileSize AS QUAD iFile = FREEFILE oFile = FREEFILE OPEN "northamerica" FOR BINARY AS #iFile OPEN "olson.txt" FOR OUTPUT AS #oFile quFileSize = LOF(#iFile) sOlsonTimeZone = SPACE$(quFileSize) GET #iFile, 1, sOlsonTimeZone CLOSE #iFile dwCount = PARSECOUNT(sOlsonTimeZone, $LF) DIM arOlson(1 TO dwCount) AS STRING PARSE sOlsonTimeZone, arOlson(), $LF FOR dwIndex = 1 TO dwCount sOlsonTimeZone = arOlson(dwIndex) ' Skip comment lines (start with #) IF ASC(sOlsonTimeZone,1) <> 35 THEN ' Skip blank lines IF LEN(sOlsonTimeZone) > 0 THEN ' Replace any tabs or carriage returns (not normally found) with spaces REPLACE ANY $TAB WITH $SPC IN sOlsonTimeZone REPLACE ANY $CR WITH $SPC IN sOlsonTimeZone ' Replace consecutive spaces with single space DO IF INSTR(sOlsonTimeZone," ") THEN REPLACE " " WITH $SPC IN sOlsonTimeZone ELSE EXIT DO END IF LOOP ' Remove leading spaces sOlsonTimeZone = LTRIM$(sOlsonTimeZone) ' Check if there are any trailing comments on the line and remove them if found dwTrailer = INSTR(sOlsonTimeZone,"#") IF dwTrailer > 0 THEN sOlsonTimeZone = LEFT$(sOlsonTimeZone,dwTrailer - 1) END IF ' Remove trailing spaces sOlsonTimeZone = RTRIM$(sOlsonTimeZone) ' At this point, can do a parse on $SPC and the first array entry will ' direct any further action WRITE #oFile, sOlsonTimeZone END IF END IF NEXT CLOSE #oFile END FUNCTION
I'm thinking of emitting a series of DATA statements to be used as an include file and the DLL can load up some internal arrays to service the supporting timezone functions.
Rick------------------------------------------------------------
sigpic
It has come to my attention that certain dubious forces are interpolating their desires in my search for Mom, apple pie and the girl you left behind. Stop it or I'll scream...
Comment
Comment