Google Grupper har inte längre stöd för nya Usenet-inlägg eller -prenumerationer. Historiskt innehåll förblir synligt.
Dismiss

Computing time difference in classical REXX

1 849 visningar
Hoppa till det första olästa meddelandet

Arthur T.

oläst,
14 jan. 2014 18:51:472014-01-14
till
I'd like to compute the time difference between two time/date
stamps. The inputs will be in the format of yyyymmdd hh:mm:ss.

Is there anything easier than computing the number of days
difference, converting to seconds, then adding the time difference,
and adjusting for partial days (e.g. if end-time is less than
start-time, subtract one day)?

I'd think this was a common operation, so someone has likely
already written and debugged code I could use. But if the answer is
in the newsgroup, my search hasn't found it.

(It probably wouldn't take me too long to write the code, but
then there's the problem in coming up with weird test examples to make
sure it's correct. I've decided that I'll probably ignore the
problems introduced by DST.)

In case it makes a difference, I'm using Regina on Windows.

--
Arthur T. - ar23hur "at" intergate "dot" com

LesK

oläst,
14 jan. 2014 23:36:552014-01-14
till
I have a routine to do that for THE, but it uses the ooRexx 'full'
option. You could use it as a base though, making appropriate adjustments.

Drop me a note if you'd like to see it.

--

Les (Change Arabic to Roman to email me)

Rony

oläst,
15 jan. 2014 03:40:152014-01-15
till
Try to locate "datergf" which does that and even more...

---rony


LesK

oläst,
15 jan. 2014 04:31:102014-01-15
till
Hmmm.... I have the 1996 OS/2 version :-)

Rony

oläst,
15 jan. 2014 08:34:112014-01-15
till
Hmm, I see. Tried to locate datergf via google in vain, hence I uploaded it to a new location for
downloading a few minutes ago.

"datergf.rex" is part of the "cronrgf" package, but can be used stand-alone as well:

http://wi.wu.ac.at/rgf/rexx/misc/cronrgf_with_datergf/CRONrgf-20111126.zip



Hint: an example from the commandline:

E:\\tmp>datergf "20120102 17:00:01", "-S", "20120101 17:00:00"
DATERGF - result: 1.00001157

Same example from within a Rexx program:

say datergf("20120102 17:00:01", "-S", "20120101 17:00:00")

output would be:

1.00001157

---

Another hint: if you just enter "datergf" on the command line you will get all options datergf
supports. However, in that particular case (invoking datergf without arguments) you will see ANSI
escape sequences (courtesy of "ScrColor.rex") for OS/2 caused colouring of the output which usually
is not available on Windows.

If you want to get rid of the ANSI escape sequences, then change the Rexx program "ScrColor.rex"
accordingly (just return empty strings instead of the ANSI escape sequences).

HTH,

---rony


Jeremy Nicoll - news posts

oläst,
15 jan. 2014 15:39:222014-01-15
till
Arthur T. <art...@munged.invalid> wrote:

> I'd like to compute the time difference between two time/date
>stamps. The inputs will be in the format of yyyymmdd hh:mm:ss.
>
> Is there anything easier than computing the number of days
>difference, converting to seconds, then adding the time difference,
>and adjusting for partial days (e.g. if end-time is less than
>start-time, subtract one day)?

I'd probably do it slightly differently by expressing each date & time as a
number of whole & fractional days, essentially adding

(hh*3600 + mm*60 + ss)/86400

to each day's base date, to get values that are easily subtracted.

This doesn't take account of problems like clock changes twice per year.

--
Jeremy C B Nicoll - my opinions are my own.

Email sent to my from-address will be deleted. Instead, please reply
to newsre...@wingsandbeaks.org.uk replacing "aaa" by "284".

Arthur T.

oläst,
15 jan. 2014 19:11:392014-01-15
till
In Message-ID:<mpro.mzgmpm...@wingsandbeaks.org.uk.invalid>,
Jeremy Nicoll - news posts <jn.nntp....@wingsandbeaks.org.uk>
wrote:

>Arthur T. <art...@munged.invalid> wrote:
>
>> I'd like to compute the time difference between two time/date
>>stamps. The inputs will be in the format of yyyymmdd hh:mm:ss.
>>
>> Is there anything easier than computing the number of days
>>difference, converting to seconds, then adding the time difference,
>>and adjusting for partial days (e.g. if end-time is less than
>>start-time, subtract one day)?
>
>I'd probably do it slightly differently by expressing each date & time as a
>number of whole & fractional days, essentially adding
>
> (hh*3600 + mm*60 + ss)/86400
>
>to each day's base date, to get values that are easily subtracted.

I realized this was a probably better way when my search turned
up a REXX program to turn date & time into a Stardate. If dategrf
(via rony) doesn't do what I need, this is what I'll probably go with.

Arthur T.

oläst,
15 jan. 2014 19:13:462014-01-15
till
In Message-ID:<lb62o0$cr2$1...@speranza.aioe.org>,
Rony <rony.fl...@wu-wien.ac.at> wrote:

>Hmm, I see. Tried to locate datergf via google in vain, hence I uploaded it to a new location for
>downloading a few minutes ago.
>
>"datergf.rex" is part of the "cronrgf" package, but can be used stand-alone as well:

Thank you. Not only do you find me a tool, but you re-search for
it, and put it where I can find it. Then you give me some examples.
It looks like the tool does so much that there might be a bit of
learning curve. But, complex tools are often worth that investment of
time.

Again, thank you.

xad...@gmail.com

oläst,
15 jan. 2014 20:03:342014-01-15
till
Although you already have a very nice solution, if you want to do it from scratch, you may take as reference the algorithms in the book:
- Practical Astronomy with your Calculator ( http://www.amazon.com/Practical-Astronomy-Calculator-Peter-Duffett-Smith/dp/0521356997 )
There you have everything that gives you the basis to develop rexx routines to make all types of calculations with time stamps.

LesK

oläst,
16 jan. 2014 00:37:322014-01-16
till
On 1/15/2014 3:39 PM, Jeremy Nicoll - news posts wrote:
> Arthur T. <art...@munged.invalid> wrote:
>
>> I'd like to compute the time difference between two time/date
>> stamps. The inputs will be in the format of yyyymmdd hh:mm:ss.
>>
>> Is there anything easier than computing the number of days
>> difference, converting to seconds, then adding the time difference,
>> and adjusting for partial days (e.g. if end-time is less than
>> start-time, subtract one day)?
>
> I'd probably do it slightly differently by expressing each date & time as a
> number of whole & fractional days, essentially adding
>
> (hh*3600 + mm*60 + ss)/86400
>
> to each day's base date, to get values that are easily subtracted.
>
> This doesn't take account of problems like clock changes twice per year.
>
That's the approach I took when comparing the date/time of a file in a
zip archive with that of the file on disk. But I used the ooRexx 'Full'
option. which returns the number of microseconds since 00:00:00.000000
on 1 Jan 0001. That feature makes it fairly simple:

Numeric Digits 18 -- needed To add the timestamps
filestamp = Date('f', dt,'S','','-') + Time('f',tm, 'N')
zipstamp = Date('f', zdt,'S','','-') + Time('f',ztm, 'N')
timediff=(zipstamp-filestamp)/1000000

From there, it's straightforward to deal with DST and convert to
convenient display units.

Rony

oläst,
16 jan. 2014 14:50:302014-01-16
till
You are very welcome, hopefully it serves your purposes.

Ad functionality: I just pointed out that there is more in there and you probably have found the
documentation at the top of the code of datergf.rex. The options are somewhat mnemonic like "WB", is
the acronym for "Week Begin" and the like.

---rony


Meddelandet har raderats

StuartKuz

oläst,
5 feb. 2020 14:44:332020-02-05
till
If the difference is between points in your code, time(E) is cool.
-Stuart
0 nya meddelanden