Announcement

Collapse
No announcement yet.

Olson Timezone DB

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Olson Timezone DB

    Is there a PB implementation for the Olson Timezone DB before I write one?
    ------------------------------------------------------------
    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...

  • #2
    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().
    Source: http://en.wikipedia.org/wiki/Zoneinfo#File_formats

    ... 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.

    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      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


      • #4
        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
        Exactly what kind of "timezone support" do you need? There may be "another way" to do it, a method sans the Olsen DB.
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          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


          • #6
            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


            • #7
              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.
              UTC 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.
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Originally posted by Michael Mattias View Post
                UTC 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.
                It seems one also has to know the rules for DST (daylight savings) in both locales in addition to the timezones active for that datetime. Many locales have a history of altering both for a myriad of reasons. Additionally, some countries based their transition dates for DST on non-Gregorian calendars. Since I'm in the neighborhood, so to speak, I thought it challenging to tackle all the above and the Olson files are simply a part of the possible solution as I dive into this area a bit deeper. I've looked into the WIN32 API and there are certainly some things that will be used and I'm also careful of the API dependencies I might use.

                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


                • #9
                  Hi Rick,

                  I think you and our other PowerBASIC time lord and date guru, Egbert Zijlema, have a lot to talk about:

                  http://zijlema.basicguru.eu/

                  I am surprised he hasn't said hello yet
                  Last edited by Marc Giao; 21 Aug 2009, 07:59 PM.
                  Regards,
                  Marc

                  Comment


                  • #10
                    Originally posted by Marc Giao View Post
                    Hi 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


                    • #11
                      Originally posted by John Gleason View Post
                      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
                      As a quick proof on concept, I put together this quick code snippet:

                      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 examined the output with Windows Notepad and initial inspection of the results seemed correct. The files I downloaded use linefeeds and not CRLF tags to separate records.

                      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

                      Working...
                      X