Conversion of date / current time to DateAndTime 
Author Message
 Conversion of date / current time to DateAndTime

Greetings Listers,
        I would like to ask for a small help from you guys. Am stuck
with the task of converting current system time to another format
specified in TextualConvention DateAndTime ( RFC 1903 ). For some
reasons, I have to use tcl for this purpose.
      In this conversion, please not that every two digits in decimal
are converted to Hex in the string for this representation.
       Example :
       Current Date - Nov 27 2002 04:18:25.00 + 00:00
       Should be represented as :  14 02 0b 1b 04 12 19 00 2b 00 00
Any help will be highly appreciated.
Mike.

 PS:

DateAndTime ::= TEXTUAL-CONVENTION
    DISPLAY-HINT "2d-1d-1d,1d:1d:1d.1d,1a1d:1d"
    STATUS       current
    DESCRIPTION
            "A date-time specification.

            field  octets  contents                  range
            -----  ------  --------                  -----
              1      1-2   year                      0..65536
              2       3    month                     1..12
              3       4    day                       1..31
              4       5    hour                      0..23
              5       6    minutes                   0..59
              6       7    seconds                   0..60
                           (use 60 for leap-second)
              7       8    deci-seconds              0..9
              8       9    direction from UTC        '+' / '-'
              9      10    hours from UTC            0..11
             10      11    minutes from UTC          0..59

            For example, Tuesday May 26, 1992 at 1:30:15 PM EDT would
be
            displayed as:

                             1992-5-26,13:30:15.0,-4:0

            Note that if only local time is known, then timezone
            information (fields 8-10) is not present."
    SYNTAX       OCTET STRING (SIZE (8 | 11))



Mon, 16 May 2005 09:41:55 GMT  
 Conversion of date / current time to DateAndTime
I suggest you look at the following man/help pages:
        clock format
        format
Quote:

> Greetings Listers,
>         I would like to ask for a small help from you guys. Am stuck
> with the task of converting current system time to another format
> specified in TextualConvention DateAndTime ( RFC 1903 ). For some
> reasons, I have to use tcl for this purpose.
>       In this conversion, please not that every two digits in decimal
> are converted to Hex in the string for this representation.
>        Example :
>        Current Date - Nov 27 2002 04:18:25.00 + 00:00
>        Should be represented as :  14 02 0b 1b 04 12 19 00 2b 00 00
> Any help will be highly appreciated.
> Mike.

>  PS:

> DateAndTime ::= TEXTUAL-CONVENTION
>     DISPLAY-HINT "2d-1d-1d,1d:1d:1d.1d,1a1d:1d"
>     STATUS       current
>     DESCRIPTION
>             "A date-time specification.

>             field  octets  contents                  range
>             -----  ------  --------                  -----
>               1      1-2   year                      0..65536
>               2       3    month                     1..12
>               3       4    day                       1..31
>               4       5    hour                      0..23
>               5       6    minutes                   0..59
>               6       7    seconds                   0..60
>                            (use 60 for leap-second)
>               7       8    deci-seconds              0..9
>               8       9    direction from UTC        '+' / '-'
>               9      10    hours from UTC            0..11
>              10      11    minutes from UTC          0..59

>             For example, Tuesday May 26, 1992 at 1:30:15 PM EDT would
> be
>             displayed as:

>                              1992-5-26,13:30:15.0,-4:0

>             Note that if only local time is known, then timezone
>             information (fields 8-10) is not present."
>     SYNTAX       OCTET STRING (SIZE (8 | 11))



Mon, 16 May 2005 13:26:57 GMT  
 Conversion of date / current time to DateAndTime

Quote:

> Greetings Listers,
>         I would like to ask for a small help from you guys. Am stuck
> with the task of converting current system time to another format
> specified in TextualConvention DateAndTime ( RFC 1903 ). For some
> reasons, I have to use tcl for this purpose.
>       In this conversion, please not that every two digits in decimal
> are converted to Hex in the string for this representation.
>        Example :
>        Current Date - Nov 27 2002 04:18:25.00 + 00:00
>        Should be represented as :  14 02 0b 1b 04 12 19 00 2b 00 00
> Any help will be highly appreciated.

    proc seconds2DateAndTime time {
        set ans ""
        set fmt {%C %y %m %d %H %M %S 0 43 0 0} ;# 43 is ascii value of '+'
        foreach elem [clock format $time -gmt true -format $fmt] {
            append ans [format "%02x " $elem]
        }
        return [string trimright $ans]
    }
    set dat [seconds2DateAndTime [clock seconds]]

However, according to the spec, should the year 2002 be represented as
"14 02" or "07 d2"?  Seems to me it should be the latter.  In that case:

    proc seconds2DataAndTime time {
        set year [format %04x [clock format $time -gmt true -format {%Y}]]
        set ans "[string range $year 0 1] [string range $year 2 3]"
        set fmt {%m %d %H %M %S 0 43 0 0}
        foreach elem [clock format $time -gmt true -format $fmt] {
            append ans [format " %02x" $elem]
        }
        return $ans
    }

Quote:
> DateAndTime ::= TEXTUAL-CONVENTION
>     DISPLAY-HINT "2d-1d-1d,1d:1d:1d.1d,1a1d:1d"
>     STATUS       current
>     DESCRIPTION
>             "A date-time specification.

>             field  octets  contents                  range
>             -----  ------  --------                  -----
>               1      1-2   year                      0..65536
>               2       3    month                     1..12
>               3       4    day                       1..31
>               4       5    hour                      0..23
>               5       6    minutes                   0..59
>               6       7    seconds                   0..60
>                            (use 60 for leap-second)
>               7       8    deci-seconds              0..9
>               8       9    direction from UTC        '+' / '-'
>               9      10    hours from UTC            0..11
>              10      11    minutes from UTC          0..59

>             For example, Tuesday May 26, 1992 at 1:30:15 PM EDT would
> be
>             displayed as:

>                              1992-5-26,13:30:15.0,-4:0

>             Note that if only local time is known, then timezone
>             information (fields 8-10) is not present."
>     SYNTAX       OCTET STRING (SIZE (8 | 11))

--
Glenn Jackman
NCF Sysadmin



Tue, 17 May 2005 00:17:06 GMT  
 Conversion of date / current time to DateAndTime
Hi Mike,

Quote:

>         I would like to ask for a small help from you guys. Am stuck
> with the task of converting current system time to another format

You need to have a good look at documentation for the [clock] command.
Most of what you need is in there.  To get the current time you'd do
[clock seconds].

Quote:
> specified in TextualConvention DateAndTime ( RFC 1903 ). [...]
>        Example :
>        Current Date - Nov 27 2002 04:18:25.00 + 00:00
>        Should be represented as :  14 02 0b 1b 04 12 19 00 2b 00 00

I'd suggest you first decompose the time you got from [clock seconds]
into fields.  You can use [clock format] for that.  You write the
format pattern so that you create a string that looks like a Tcl list
(make sure that none of the numbers has extra leading zeros).  After
that you use the [binary format] command to create your intended
target format.

It should be possible to do the whole thing in four commands.

Hope this help, benny



Tue, 17 May 2005 02:04:24 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Touching a file (set to current time and date)

2. Displaying current time/date

3. COBOL II get current date and time

4. CURRENT-DATE, TIME-OF-DAY special registers (IBM)

5. CURRENT-DATE, TIME-OF-DAY special regis

6. Current date and time

7. Current Time and Date?

8. Getting the current date/time in tcl/tk

9. Create Time / date or Modified Time / date of a txt file

10. convert labview date/time to excel date/time

11. DOS compressed date/time into real date/time

12. Date-Time/TOD clock conversion (was Re: (no subject given))

 

 
Powered by phpBB® Forum Software