Author Topic: HFS Scripting cmd: time and filetime  (Read 58 times)

0 Members and 1 Guest are viewing this topic.

Offline newbie

  • Occasional poster
  • *
  • Posts: 27
    • View Profile
HFS Scripting cmd: time and filetime
« on: December 03, 2019, 11:10:31 PM »
I want to figure out the time difference between current server time and filetime of a file.
From https://www.rejetto.com/wiki/index.php/HFS:_scripting_commands
it looks like:
filetime returns a double value based on Delphi time ie days since 12/30/1899
&
time returns a value based on the optional argument (YY:MM:DD:HH:NN:SS) something like 2019:12:03:18:10:59

How can I get both times in one format, so that I can get the time since the file was created on the server.

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1900
    • View Profile
Re: HFS Scripting cmd: time and filetime
« Reply #1 on: December 03, 2019, 11:29:49 PM »
quick answer:
a track to determine the time elapsed between two instants
http://rejetto.com/forum/index.php?topic=6710.msg1041312#msg1041312
  use the date of the file in digital format as given par %now%

Offline newbie

  • Occasional poster
  • *
  • Posts: 27
    • View Profile
Re: HFS Scripting cmd: time and filetime
« Reply #2 on: December 03, 2019, 11:35:08 PM »
nm. I figured it out based on the comment here:
https://stackoverflow.com/questions/57184472/javascript-date-to-delphi-tdatetime

A Unix date/time is represented as the number of seconds since January 1 1970 00:00:00 UTC.
Delphi has a UnixDateDelta constant in the SysUtils unit which is defined as 25569, the number of days from December 31 1899 to January 1 1970.

So, using 25569, I was able to convert HFS time|YYYY:MM:DD:HH:NN:SS  to time_t, then do a difftime to get (double) seconds, divide by 86400 to get days, and then add 25569 to get the time in Delphi time.

But just saw your comment %now% works better. Thanks.

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1900
    • View Profile
Re: HFS Scripting cmd: time and filetime
« Reply #3 on: December 03, 2019, 11:49:53 PM »
I do not remember which one but one of them will fit before


{.calc|(%now% - %item-modified-dt%).}

provides the difference of dates in number of days


after fumbling here is the final result

Code: [Select]
{.set|delay|{.calc|%now%-%item-modified-dt%.}.}
{.set|days|{.substring||.|{.^delay.}.}.}
{.set|delay|{.calc|({.^delay.}-{.^days.})*24.}.}
{.set|hours|{.substring||.|{.^delay.}.}.}
{.set|delay|{.calc|({.^delay.}-{.^hours.})*60.}.}
{.set|mins|{.substring||.|{.^delay.}.}.}
{.set|delay|{.calc|({.^delay.}-{.^mins.})*60.}.}
{.set|secs|{.substring||.|{.^delay.}.}.}
{.^days.}d  {.^hours.}h  {.^mins.}m  {.^secs.}s
« Last Edit: December 04, 2019, 12:22:21 AM by Mars »