Re: how to compare two time
From: Lueko Willms (l.willms_at_jpberlin.de)
Date: 10/11/04
- Next message: Lueko Willms: "Re: OT: The Ultimate in Outsourcing"
- Previous message: Lueko Willms: "Display enhancements (was: OFF Topic)"
- In reply to: William Cai: "Re: how to compare two time"
- Next in thread: William Cai: "Re: how to compare two time"
- Reply: William Cai: "Re: how to compare two time"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 11 Oct 2004 08:26:00 GMT
. Am 11.10.04
schrieb William.Cai@gmail.com (William Cai)
auf /COMP/LANG/COBOL
in ckcmcj$bf2$1@mail.cn99.com
ueber Re: how to compare two time
WC> Hey, I know what you mean. But in C/C++ world, you just need to do
WC> the following thing.
WC>
WC> int begin = time(NULL);
WC> ... ...
WC> int end = time(NULL);
WC>
WC> int val = end - begin;
You could even use the "difftime" function.
BUT ... you wrote "int", but is "int" really the type for the
"time" function? The standard says the type is "time_t", and that is
implementor defined: "the range and precision of times representable
in clock_t and time_t are implementation-defined".
. Also, on the "time" function: "the encoding of the value is
unspecified", so you don't really know what "val" represents -
minutes? seconds? milliseconds?
Similar the definition of the structure "tm", which "shall contain
at least the following members, _in any order"._
See the C standard, chapter 7.23
WC> How about COBOL?
The corresponding structure in COBOL to the "tm" structure is well
defined, and you can see it when you look at FUNCTION CURRENT-DATE or
FUNCTION DATE-COMPILED, and so well defined with the components in
order of significance so that it allows a sensible comparison of those
structures for GREATER or LESS, without looking at the individual
components (maybe one has to omit the time-zone offset, which is btw,
not included in C's "tm" structure).
COBOL also provides date conversion functions, most importantly
INTEGER-OF-DATE and DATE-OF-INTEGER which provides or uses a serial
day number with the epoch of Janary 1, 1601 as day number 1.
When you want to compare times, it is better to use these functions
instead of the ACCEPT ... FROM TIME and ACCEPT ... FROM DATE.
Converting clock times from hour, minute, second to an integer and
vice versa does not require special functions because of the regular
structure - an hour has always 60 mintues, and a minute has always 60
seconds, except when there is a leap second inserted.
The difficulty arises only when you want to have a single number
representing a point in time, including both a serial day number and
the time of day.
For this case, your compiler either provides a system function
giving the seconds or milliseconds passed since some not so recent
epoch (UNIX: Midnight at January 1, 1970) which you can use, or you
calculate your own number using the values provided by FUNCTION
CURRENT-DATE and e.g. FUNCTION INTEGER-OF-DATE(19700101), either
calculating the number of seconds elapsed, or, as some applications
do, using the time of day as a fractional part of a _real_ number for
date-time (instead of an integer). It depends on the _purpose_ of your
time comparison which you did not mention in your question.
Sure, all those FUNCTIONs arrived in the COBOL standard quite late,
but then they have some improvements over C's "time" library, e.g. the
FUNCTION INTEGER-OF-DATE which for many applications is more important
than expressing a complete time stamp in seconds or fractions of
seconds.
Maybe the main difference for YOU between COBOL and C or C++ is that
you have been tought the latter in school and hardly know the former.
This is about to change, it seems to me.
Have fun,
yours,
Lüko Willms http://www.mlwerke.de
/--------- L.WILLMS@jpberlin.de -- Alle Rechte vorbehalten --
"Kein Land kann seine Probleme in dieser globalisierten Welt allein
auf sich gestellt lösen. Entweder wir retten uns alle zusammen oder
wir gehen zusammen unter. Heute mehr denn je gilt das Wort von José
Martí: Das Vaterland ist die ganze Menschheit."
- Fidel Castro, Caracas (Veneuzuela), 3. Februar 1999
- Next message: Lueko Willms: "Re: OT: The Ultimate in Outsourcing"
- Previous message: Lueko Willms: "Display enhancements (was: OFF Topic)"
- In reply to: William Cai: "Re: how to compare two time"
- Next in thread: William Cai: "Re: how to compare two time"
- Reply: William Cai: "Re: how to compare two time"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|