• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. ISO 8601 timestamp

Stats

  • Locked Locked
  • Replies 4
  • Subscribers 143
  • Views 14711
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ISO 8601 timestamp

Yaosan Yeo
Yaosan Yeo over 13 years ago

I'm trying to work with timestamp in ISO 8601 format. The timestamp looks like this: "2012-08-07T16:38:45.693245Z". I want to construct a report field which displays this date in one of the columns. I know in SKILL the standard time string looks more like this: "Aug  1 12:00:32 2012". Is there an easy way to convert my input time string to the time string SKILL recognize?

I've tried to format the input time string then use "date" in command line to convert the time stamp but it is really really slow:

date -d "2012-08-07 16:38:45.693245 UTC" "+%b %_d %k:%m:%S %Y"

Is there another way around this problem? Thanks!

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 13 years ago

    I just wrote this - it uses the pcre (Perl Compatible Regular Expression) functions (in IC61) to parse the ISO 8601 format date string, and then the "tm" functions to convert to and from a time structure - and then to a SKILL date string. May need some further work because I just threw this together...

    /* abISO8601.il
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       Aug 08, 2012 
    Modified   
    By         
    
    Functions to convert dates in ISO8601 format to either "tm"
    structures or a SKILL date string.
    
    Note that this doesn't handle time zones - so may need some
    adjustment for timezones / daylight saving time (not sure).
    
    ***************************************************
    
    SCCS Info: @(#) abISO8601.il 08/08/12.06:36:34 1.1
    
    */
    
    /***************************************************************
    *                                                              *
    *                  (abISO8601toTm dateString)                  *
    *                                                              *
    * Attempts to convert an ISO8601 formatted date string into a  *
    *                       "tm" structure.                        *
    *                                                              *
    ***************************************************************/
    
    (defun abISO8601toTm (dateString)
      (let (pattern tm slot)
        ;--------------------------------------------------------------------
        ; Note ignores anything after decimal point in seconds, as time
        ; functions in SKILL do not support finer granularity. Also the
        ; time zone is ignored. The pattern below should support both
        ; basic and extended format
        ;--------------------------------------------------------------------
        (setq pattern (pcreCompile
                        "(\\d{4})-?(\\d{2})-?(\\d{2})[T ]?(\\d{2}):?(\\d{2}):?(\\d{2})"
                        ))
        (when
          (pcreExecute pattern dateString)
          ;------------------------------------------------------------------
          ; Create an "empty" tm structure
          ;------------------------------------------------------------------
          (setq tm (timeToTm 0))
          (setq slot 1)
          (foreach (field correction) 
                   '(tm_year tm_mon tm_mday tm_hour tm_min tm_sec)
                   '(1900 1 0 0 0 0)
                   ;---------------------------------------------------------
                   ; Pull out each field from the pattern, convert to
                   ; integer, and apply a correction (subtraction) 
                   ; and then store in the correct field in the tm
                   ; structure
                   ;---------------------------------------------------------
                   (putprop tm (difference
                                 (atoi (pcreSubstitute
                                         pattern 
                                         (sprintf nil "\\%d" (postincrement slot))))
                                 correction)
                            field)
                   )
          ;------------------------------------------------------------------
          ; could do timeToTm(tmToTime(tm)) here to fill in other fields
          ; but doesn't seem really necessary
          ;------------------------------------------------------------------
          tm
          )
        )
      )
    
    /****************************************************************
    *                                                               *
    *                (abISO8601toString dateString)                 *
    *                                                               *
    * Convert an ISO8601 date string into SKILL's usual date format *
    *                                                               *
    ****************************************************************/
    
    (defun abISO8601toString (dateString)
      (timeToString (tmToTime (abISO8601toTm dateString)))
      )

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Yaosan Yeo
    Yaosan Yeo over 13 years ago

    Hi Andrew, thanks for your wonderful code, it works great! There's one minor issue with the code in the pcreSubstitute section, the "pattern" needs to be removed to prevent "only 1 argument expected" error.

    Somehow the time string returned is off by one hour, e.g. 21:53:13 in the input date string becomes 22:53:13 in the output time string. What I did is manually turn on DST in the tm structure:

    tm->tm_isdst = 1
    tm ; return

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 13 years ago

    For the pcreSubstitute() issue, my guess is that you're using IC614 or earlier. In that version you could only specify the string. From IC615 the definition is:

    pcreSubstitute(
    [o_pcreObject]
    t_string
    )
    => t_result | nil

    If o_pcreObject is not provided, pcreSubstitute copies the input
    string and substitutes all pattern tags in it using the corresponding
    matched strings from the last pcreExecute/pcreMatch* operation.

    So I was passing in the optional pattern object. So missing it out is OK - it will work in both IC614 and IC615.

    As for the daylight saving time - you could initialize the tm structure using timeToTm(stringToTime(getCurrentTime())) rather than timeToTm(0) which should give the current DST setting - but whether that's right for the time in question is another matter...

    I wasn't really sure what the "right" thing to do was here...

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Yaosan Yeo
    Yaosan Yeo over 13 years ago
    Thanks Andrew for the clarification. I'm using 614 indeed.
     
    As for the DST, I'm only getting the proper UTC time if I turn on DST in the tm structure. It's interesting that I could pass current time to get the current DST in the tm structure, but I guess I'll run into off by 1 hour error again once DST ends.
     
    So, I'll just turn it on always for now until I run into issues again. :)
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information