mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-17 10:23:46 +00:00
library/time.m: Deprecate non-pure functions `localtime/1' and `mktime/1'. They depend on the current time zone, which depends on the environment that the program is running in, and may also be changed at run time (e.g. by setting the environment variable "TZ"). Add replacement predicates `localtime/4' and `mktime/4' that thread the I/O state. Deprecate the non-pure function `ctime/1'. It does not seem necessary to add a pure replacement for it, being a minor convenience at best. Try to clarify some documentation. library/calendar.m: Conform to above changes. tests/hard_coded/dst_test.m: tests/hard_coded/time_test.m Conform to above changes. Update code style. extras/curs/samples/nibbles.m: extras/graphics/easyx/samples/bounce.m: extras/graphics/easyx/samples/mclock.m: extras/log4m/log4m.m: Conform to above changes. NEWS: Announce changes.
34 lines
800 B
Mathematica
34 lines
800 B
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module time_test.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module maybe.
|
|
:- import_module time.
|
|
:- import_module float.
|
|
|
|
main(!IO) :-
|
|
time(Time, !IO),
|
|
localtime(Time, LocalTM, !IO),
|
|
mktime(LocalTM, MkTime, !IO),
|
|
Diff = difftime(Time, MkTime),
|
|
( if Diff >= 0.0, Diff < 1.0 then
|
|
io.write_string("mktime succeeded\n", !IO)
|
|
else
|
|
io.write_string("mktime failed\n", !IO)
|
|
),
|
|
|
|
% Sunday 2001-01-07 03:02:01
|
|
TM = tm(101, 0, 7, 3, 2, 1, 6, 0, no),
|
|
io.write_string(asctime(TM), !IO),
|
|
io.nl(!IO).
|