[comp.os.vms] Printing file age via DCL

ZSYJKAA@WYOCDC1.BITNET (Jim Kirkpatrick 307 766-5303) (02/09/88)

I have a simple problem nobody here seems to be able to solve (we're fairly
new to VMS) which is, how to display a file's age via DCL.  I can get
the revision date and time via F$FILE_ATTRIBUTES, but how do I subtract this
(which is a character string) from the current date and time (another string)
and end up with something meaningful (such as DELTA time format)?  I can't
see how to do it via F$CVTIME though I tried F$CVTIME(-RDT) and all it gave
me was midnight of today.  I can't believe this would be difficult in DCL
but it sure isn't obvious to me!

ERIC@UOFT02.BITNET (Eric) (02/16/88)

In-Reply-To:  your letter rec'd 14-FEB-1988 14:38

From:   IN%"INFO-VAX@KL.SRI.COM" 14-FEB-1988 14:38
To:     Eric Rostetter <ERIC@UOFT02>
Subj:   Printing file age via DCL

> I have a simple problem nobody here seems to be able to solve (we're fairly
> new to VMS) which is, how to display a file's age via DCL.  I can get
> the revision date and time via F$FILE_ATTRIBUTES, but how do I subtract this
> (which is a character string) from the current date and time (another string)
> and end up with something meaningful (such as DELTA time format)?  I can't
> see how to do it via F$CVTIME though I tried F$CVTIME(-RDT) and all it gave
> me was midnight of today.  I can't believe this would be difficult in DCL
> but it sure isn't obvious to me!

The following is not what you asked for, but maybe it will help you anyway.
It types a file if the file has been changed within the last three  days...
To change the period of time,   simply change the constant date/time (delta
format) in the first line (currently 03-00:00).   Maybe you can modify this
to do what you want...  Then again, maybe not...

Eric Rostetter
Eric @ uoft02.bitnet

cfchiesa@bsu-cs.UUCP (Sir Xetwnk) (02/16/88)

In article <880208133256.00001457.HBKK.83@WYOCDC1>, ZSYJKAA@WYOCDC1.BITNET (Jim Kirkpatrick 307 766-5303) writes:
> I have a simple problem nobody here seems to be able to solve (we're fairly
> new to VMS) which is, how to display a file's age via DCL.  I can get
> the revision date and time via F$FILE_ATTRIBUTES, but how do I subtract this
> (which is a character string) from the current date and time (another string)
> and end up with something meaningful (such as DELTA time format)?  I can't
> see how to do it via F$CVTIME though I tried F$CVTIME(-RDT) and all it gave
> me was midnight of today.  I can't believe this would be difficult in DCL
> but it sure isn't obvious to me!

I thought I had the complete answer for you, but after adapting what I had to
your purposes, I find that I only have HALF the answer.  I confess to some
difficulty with the DD-MMM-YYYY portion of the time fields, but the following
should suffice to subtract the HH:MM:SS portions...  It may be useful for 
SOMETHING...

$ r_time = f$cvtime(f$file("''p1'","RDT"),,"time")
$ c_time = f$cvtime(,,"time")
$ write sys$output "Interval = ",f$cvtime("''r_time'-''c_time'",,"time")
$ exit



Chris Chiesa
Ball State University
Muncie, IN


<><><><><><><><><><><><><><><><><><><><><><><><><><><><> Chris Chiesa <><><><><>
<> {ihpn4|seismo}!{iuvax|pur-ee}!bsu-cs!cfchiesa                              <>
<> cfchiesa@bsu-cs.UUCP                                                       <>
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

u3369429@ucsvc.dn.mu.oz (02/19/88)

In article <2123@bsu-cs.UUCP>, cfchiesa@bsu-cs.UUCP (Sir Xetwnk) writes:
> In article <880208133256.00001457.HBKK.83@WYOCDC1>,
>  ZSYJKAA@WYOCDC1.BITNET (Jim Kirkpatrick 307 766-5303) wrote:
>> I have a simple problem nobody here seems to be able to solve (we're fairly
>> new to VMS) which is, how to display a file's age via DCL.  I can get
>> the revision date and time via F$FILE_ATTRIBUTES, but how do I subtract this
>> (which is a character string) from the current date and time (another string)
>> and end up with something meaningful (such as DELTA time format)?  I can't
>> see how to do it via F$CVTIME though I tried F$CVTIME(-RDT) and all it gave
>> me was midnight of today.  I can't believe this would be difficult in DCL
>> but it sure isn't obvious to me!
> 
> I thought I had the complete answer for you, but after adapting what I had to
> your purposes, I find that I only have HALF the answer.  I confess to some
> difficulty with the DD-MMM-YYYY portion of the time fields, but the following
> should suffice to subtract the HH:MM:SS portions...  It may be useful for 
> SOMETHING...
> 
> $ r_time = f$cvtime(f$file("''p1'","RDT"),,"time")
> $ c_time = f$cvtime(,,"time")
> $ write sys$output "Interval = ",f$cvtime("''r_time'-''c_time'",,"time")
> $ exit

Well, may be here is the rest of the answer.
Some time last year, I posted my DCL subroutines JULIAN and GREGOR.
If you use them you end up with something like:

$ CDT=F$File_Attributes(P1,"CDT")
$ Now=F$Time()
$ Call Julian "''CDT'" YJDay1 AJDay1
$ Call Julian "''Now'" YJDay2 AJDay2
$!
$ Write SYS$Output F$FAO("Age: !SL day!%S ",AJDay2-AJDay1), -
	F$CVTime("''F$CVTime(Now,,"TIME")'-''F$CVTime(CDT,,"TIME")'",,"TIME")

Hows'zat?

Michael Bednarek, Institute of Applied Economic and Social Research (IAESR)
   //  Melbourne University,Parkville 3052, AUSTRALIA, Phone:+61 3 344 5744
 \X/   Domain:u3369429@{murdu.oz.au | ucsvc.dn.mu.oz.au} | mb@munnari.oz.au
       "bang":...UUNET!munnari!murdu!u3369429     PSI%23343000301::U3369429
"POST NO BILLS."


Here is the complete VMS_SHAR'ed procedure:

$!...................... Cut on the dotted line and save ......................
$! VAX/VMS archive file created by VMS_SHAR V-5.04 04-Feb-1988
$! which was written by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au)
$! To unpack, simply save and execute (@) this file.
$!
$! This archive was created by U3369429 (Michael Bednarek)
$! on Friday 19-FEB-1988 12:43:55.95
$!
$! It contains the following 1 file:
$! FILE_AGE.COM
$!=============================================================================
$Set Symbol/Scope=(NoLocal,NoGlobal)
$Version=F$GetSYI("VERSION")
$If Version.ges."V4.4" then goto Version_OK
$Write SYS$Output "Sorry, you are running VMS ",Version, -
", but this procedure requires V4.4 or higher."
$Exit 44
$Version_OK:CR[0,8]=13
$Pass_or_Failed="failed!,passed."
$Goto Start
$Convert_File:
$Read/Time_Out=0/Error=No_Error1/Prompt="creating ''File_is'" SYS$Command ddd
$No_Error1:Define/User_Mode SYS$Output NL:
$Edit/TPU/NoSection/NoDisplay/Command=SYS$Input/Output='File_is' -
VMS_SHAR_DUMMY.DUMMY
f:=Get_Info(Command_Line,"File_Name");b:=Create_Buffer("",f);
o:=Get_Info(Command_Line,"Output_File");Set(Output_File,b,o);
Position(Beginning_of(b));Loop x:=Erase_Character(1);Loop ExitIf x<>"V";
Move_Vertical(1);x:=Erase_Character(1);Append_Line;
Move_Horizontal(-Current_Offset);EndLoop;Move_Vertical(1);
ExitIf Mark(None)=End_of(b) EndLoop;Position(Beginning_of(b));Loop
x:=Search("`",Forward,Exact);ExitIf x=0;Position(x);Erase_Character(1);
If Current_Character='`' then Move_Horizontal(1);else
Copy_Text(ASCII(INT(Erase_Character(3))));EndIf;EndLoop;Exit;
$Delete VMS_SHAR_DUMMY.DUMMY;*
$Checksum 'File_is
$Success=F$Element(Check_Sum_is.eq.CHECKSUM$CHECKSUM,",",Pass_or_Failed)+CR
$Read/Time_Out=0/Error=No_Error2/Prompt=" CHECKSUM ''Success'" SYS$Command ddd
$No_Error2:Return
$Start:
$File_is="FILE_AGE.COM"
$Check_Sum_is=962166452
$Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X$ CDT=F$File_Attributes(P1,"CDT")
X$ Now=F$Time()
X$ Call Julian "''CDT'" YJDay1 AJDay1
X$ Call Julian "''Now'" YJDay2 AJDay2
X$!
X$ Write SYS$Output F$FAO("Age: !SL day!%S ",AJDay2-AJDay1), -
X`009F$CVTime("''F$CVTime(Now,,"TIME")'-''F$CVTime(CDT,,"TIME")'",,"TIME")
X$ Exit
X$Julian: Subroutine
X$! Copyright (c) `169 1987, by Michael Bednarek
X$! The distribution of this file is unrestricted as long as this notice
X$! remains intact.
X$ On Warning then Exit
X$! Converts Gregorian Date into Julian Day
X$! This is a straight translation from an old Fortran routine of mine.
X$ M2=" 0,31,59,90,120,151,181,212,243,273,304,334"
X$! Input:
X$! P1 = Date in absolute format as returned from F$CVTIME
X$!
X$! Output:
X$! P2 = YJDay = Julian Day in this year
X$! P3 = AJDay = Julian Day since 1-Jan-0001 A.D
X$!`009`009(can be used as input to GREGOR)
X$!
X$ Year =F$Integer(F$CVTime(P1,,"Year"))
X$ Month=F$Integer(F$CVTime(P1,,"Month"))
X$ Day  =F$Integer(F$CVTime(P1,,"Day"))
X$!
X$! detect leap year
X$ Leap= Year-Year/400*400.eq.0 .or. -
X`009Year-Year/100*100.ne.0 .and. Year-Year/4*4.eq.0
X$!
X$! Calculate this year's Julian Day
X$ 'P2==F$Integer(F$Element(Month-1,",",M2))+Day
X$ If Month.gt.2 .and. Leap then 'P2=='P2+1
X$!
X$! Calculate the Absolute Julian Day
X$ Year=Year-1
X$ 'P3==Year*365+Year/4-Year/100+Year/400+'P2
X$ EndSubroutine
X$Gregor: Subroutine
X$! Copyright (c) `169 1987, by Michael Bednarek
X$! The distribution of this file is unrestricted as long as this notice
X$! remains intact.
X$ On Warning then Exit
X$! Converts Julian Day into Gregorian Date
X$! Although this routine is not required in this context, I thought I'd
X$! include it anyway.
X$! Input:
X$! P1 = AJDay = Julian Day since 1-Jan-0001 A.D. (as obtained from JULIAN)
X$!
X$! Output:
X$! P2 = Date in absolute format (dd-Mon-yyyy)
X$ M1=" 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31"
X$ M3="Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"
X$!
X$ i=P1
X$ im=i/146097
X$ Year=im*400
X$ i=i-im*146097
X$!
X$ im=i/36524
X$ Year=Year+im*100
X$ i=i-im*36524
X$!
X$ im=i/1461
X$ Year=Year+im*4
X$ i=i-im*1461
X$!
X$ im=(i+364)/365-1
X$ Year=Year+im
X$!
X$ YJDay=P1-Year*365-Year/4+Year/100-Year/400
X$ Year=Year+1
X$!
X$ Leap= Year-Year/400*400.eq.0 .or. -
X`009Year-Year/100*100.ne.0 .and. Year-Year/4*4.eq.0
X$!
X$ If .not.Leap`009then M1[5,2]:="28"`009! Grr, this ...
X$ If Leap`009then M1[5,2]:="29"`009! is ugly!
X$ n1=0
X$ Month=0
X$Loop:
X$ Month=Month+1
X$ n2=n1
X$ n1=n1+F$Integer(F$Element(Month-1,",",M1))
X$ If YJDay.le.n1 then goto Done
X$ If Month.lt.12 then goto Loop
X$Done:
X$ Day=YJDay-n2
X$ Month=F$Element(Month-1,",",M3)
X$ 'P2==F$CVTime("''Day'-''Month'-''Year'","Absolute","Date")
X$ EndSubroutine
$GoSub Convert_File
$Exit