Operating System - OpenVMS
1829122 Members
1956 Online
109986 Solutions
New Discussion

Converting COMPARISON to ABSOLUTE time

 
SOLVED
Go to solution
Jack Trachtman
Super Advisor

Converting COMPARISON to ABSOLUTE time

Hopefully I'm just missing something obvious, but I don't see a DCL lexical func that will convert COMPARSION time back to ABSOLUTE time.

I often store COMPARISON times in records so that I can, well, compare times. Now, I'd like be able to use some the F$CVTIME options to get WEEKDAY, etc, but don't see an easy way to convert the time back to ABSOLUTE, which F$CVTIME seems to require. (Also - I noticed that the F$DELTA lexical only uses ABSOLUTE times).
12 REPLIES 12
EdgarZamora
Trusted Contributor

Re: Converting COMPARISON to ABSOLUTE time

Not sure exactly what you're asking, but f$cvtime is capable of outputting absolute time. "ABSOLUTE" in the second argument which is the output time format.
Dean McGorrill
Valued Contributor

Re: Converting COMPARISON to ABSOLUTE time

it will do absolute, here a what day I
use. Dean
**********
$!
$! whatday.com dean mcgorrill 08-mar-2007
$!
$! return weekday and time, pass a date via p1 parameter
$!
$ wo=="write sys$output"
$ daytime = f$cvtime(p1,,"weekday") + " " + -
f$cvtime(p1,"absolute","datetime")
$ daytime = f$extract(0,f$locate(".",daytime),daytime)
$ wo daytime
$ exit 1
Robert Gezelter
Honored Contributor

Re: Converting COMPARISON to ABSOLUTE time

Jack,

Interesting. This seems to be an error in the documentation that was fixed sometime between Version 6.2 and Version 8.2 (I do not have the time to narrow it further).

Off the top of my head, given the fact that F$CVTIME does not do it directly, I would engage in a little slight of hand. F$CVTIME is still known to work for DELTA and combination times. I would use F$ELEMENT to extract the year, insert it into a January 1, xxxx absolute date and use the rest of the comparison date to create a delta time, using F$CVTIME to then get the various components.

If I am not being clear, please let me know.

- Bob Gezelter, http://www.rlgsc.com
Jon Pinkley
Honored Contributor
Solution

Re: Converting COMPARISON to ABSOLUTE time

Jack,

You are not missing anything, there is no lexical function to convert from ABSOLUTE format to DELTA format (at least not that I am aware of).

It can be done in one line of DCL, although it isn't pretty. Because the COMPARISON format is well defined, we can extract the year, and day without a problem, the trick is to convert the numerical month to the three character month name abreviation. The easiest way to do that is with the f$element function.

Here's the an example converting a comparision time in the symbol ct to an absolute time in symbol at.

Note: it does not handle DELTA times.

$ ct=f$cvtime("")
$ sho sym ct
CT = "2007-08-08 15:12:09.25"
$ at=f$extract(8,2,ct)+"-"+f$element(f$extract(5,2,ct),",",",JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC")+"-"+f$extract(0,4,ct)+f$extract(10,12,ct)
$ sho sym at
AT = "08-AUG-2007 15:12:09.25"

It would be nice to have an F$CVCOMPARISON_TIME or F$CVCTIME function with an optional "DCL" qualifier to place a ":" between the date and time.

Here's a more understandable version (not tested, just typed in)

$ dd = f$extract(8,2,ct)
$ mm = f$extract(5,2,ct)
$ mmm = f$element(mm,"|","|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC")
$ yyyy = f$extract(0,4,ct)
$ time = f$extract(11,11,ct)
$ at = dd + "-" + mmm + "-" + yyyy + " " + time

Jon
it depends
Jon Pinkley
Honored Contributor

Re: Converting COMPARISON to ABSOLUTE time

What I meant was "there is no lexical function to comvert from COMPARISON time to ABSOLUTE time" Sorry for the confusion.

Jon
it depends
Hein van den Heuvel
Honored Contributor

Re: Converting COMPARISON to ABSOLUTE time

Using DCL you'll have to hard-code the conversion. You can avoid coding up the month table by using a second line to grab the month and exploiting f$cvtime (as Bob suggests). The amount of typing is similar.

$ CT = "2007-01-01 15:12:09.25"
$ x = 31*f$extr(5,2,ct)-31
$ write sys$output f$extr(8,2,CT)+"-"+f$elem(1,"-",f$cvtime("1-JAN +''x'-","ABSOLUTE"))+"-"+f$extr(0,4,ct)+f$ext(10,99,ct)
01-JAN-2007 15:12:09.25

$ CT = "2007-12-31 15:12:09.25"
$ x = 31*f$extr(5,2,ct)-31
$ write sys$output f$extr(8,2,CT)+"-"+f$elem(1,"-",f$cvtime("1-JAN +''x'-","ABSOLUTE"))+"-"+f$extr(0,4,ct)
31-DEC-2007

The helper variable 'x' is a number of days since the start of the year garantueed to be in te right month, but an slowly increasing day in each month.

fwiw,
Hein.

Jack Trachtman
Super Advisor

Re: Converting COMPARISON to ABSOLUTE time

Thanks all.

You've confirmed what I found, and have given me some ideas.
Jon Pinkley
Honored Contributor

Re: Converting COMPARISON to ABSOLUTE time

After thinking a bit more about this, instead of a new lexical function, it would probably be better to modify f$cvtime to accept a fourth parameter, input-format, that would default to "ABSOLUTE" to be compatible with existing code.
Specifcally, it would be nice if the following was allowed and worked.

$ AT = lib$cvtime("2007-01-02 17:59:59.27","ABSOLUTE",,"COMPARISON") ! not implemented
$ show symbol at
AT = "02-JAN-2007 17:59:59.27" ! this is just a wishlist

Jon
it depends
Jack Trachtman
Super Advisor

Re: Converting COMPARISON to ABSOLUTE time

Jon,

I agree with your suggested addition, but I'd also like F$CVTIME and F$DELTA to accept any time format as input!
Jon Pinkley
Honored Contributor

Re: Converting COMPARISON to ABSOLUTE time

Jack,

Can you provide some examples of what you would expect to work, with input and output? "any time format as input" is a bit ambiguous.

Jon

P.S. Does anyone know if there is anything like the old DECUS SIR (System Improvement Request) still around? I have seen references to "Advocacy" but don't know where it is or if it is still active.
it depends
Hein van den Heuvel
Honored Contributor

Re: Converting COMPARISON to ABSOLUTE time

I'd be happy enough if a date string starting with 4 numerics and a dash (2007-) outside the range 1..31 would simply indicate a comparison time format. That particular combo is currently invalid as it is not a valid day-in-the-month.

The only price to pay for that convention would be the inability to default to the current year. For example, 20 august could not be: "-08-20" because this already means today minus 8 days and 20 hours.
Maybe 0000- or 0- can be used to express 'current year'.

A nice benefit of the comparison time is that it is language independend. (btw... the 'JAN' I hardcoded in my earlier example works in a good many western languages)

Cheers,
Hein.
John Gillings
Honored Contributor

Re: Converting COMPARISON to ABSOLUTE time

Date manipulation in DCL has improved in recent times. Most recently with F$DELTA. F$CVTIME was a huge step forward back in V5, but there's still several large holes, such as Jack's observation in this thread.

OpenVMS already has a fairly general mechanism for dealing with the multitude of possible date/time formats using the LIB$ date/time formatting routines. See LIB$INIT_DATE_TIME_CONTEXT and friends for details.

It's effectively a $FAO like format control string to define the position and format of various components of date and time values. See the default absolute time format:

$ SHOW LOGICAL/TABLE=*DT*

(LNM$DT_FORMAT_TABLE)

"LIB$DATE_FORMAT_001" = "!DB-!MAAU-!Y4"
"LIB$TIME_FORMAT_001" = "!H04:!M0:!S0.!C2"

Using this mechanism, a generic date conversion lexical function would accept an input date/time string and format string, and an output format string:

output=F$FORMAT_DATE(date_in [,[in_format] [,[out_format]]])

Converting from comparison format to absolute format would therefore be:

$ abs=F$FORMAT_TIME(comp,-
"!Y4-!MM-!DD !H04:!M0:!S0.!C2",-
"!DB-!MAAU-!Y4 !H04:!M0:!S0.!C2")

or, since a missing format string would use the system default, the second format string could be omitted. I'd also expect to be able to specify a logical name as the format string.

I don't know if HP has a working method for users to request enhancements. I'd guess that logging a case against a service contract and asking the engineer to submit a formal request to engineering would be the most likely to succeed.
A crucible of informative mistakes