From d51a89c815dd2f5c433b6d3995e04e8241b60233 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Tue, 16 Aug 2011 13:31:59 +0000 Subject: [PATCH] fix time routines --- library/dialect/swi.yap | 39 +++++++++++++++++++++++++++++++---- library/dialect/swi/fli/swi.c | 27 ------------------------ 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/library/dialect/swi.yap b/library/dialect/swi.yap index 811dfe487..7e1a78247 100755 --- a/library/dialect/swi.yap +++ b/library/dialect/swi.yap @@ -10,6 +10,7 @@ chdir/1, compile_aux_clauses/1, convert_time/2, + convert_time/8, '$declare_module'/5, '$set_predicate_attribute'/3, stamp_date_time/3, @@ -91,7 +92,6 @@ :- yap_flag(autoload,true). - :- set_prolog_flag(user_flags,silent). % Time is given as a float in SWI-Prolog. @@ -168,9 +168,40 @@ cvt_bindings([[Name|Value]|L],[AName=Value|Bindings]) :- chdir(X) :- cd(X). -% Time is received as int, and converted to "..." -% ctime is a built-in. -convert_time(X,Y) :- swi:ctime(X,Y). +%% convert_time(+Stamp, -String) +% +% Convert a time-stamp as obtained though get_time/1 into a textual +% representation using the C-library function ctime(). The value is +% returned as a SWI-Prolog string object (see section 4.23). See +% also convert_time/8. +% +% @deprecated Use format_time/3. + + +convert_time(Stamp, String) :- + format_time(string(String), '%+', Stamp). + +%% convert_time(+Stamp, -Y, -Mon, -Day, -Hour, -Min, -Sec, -MilliSec) +% +% Convert a time stamp, provided by get_time/1, time_file/2, +% etc. Year is unified with the year, Month with the month number +% (January is 1), Day with the day of the month (starting with 1), +% Hour with the hour of the day (0--23), Minute with the minute +% (0--59). Second with the second (0--59) and MilliSecond with the +% milliseconds (0--999). Note that the latter might not be accurate +% or might always be 0, depending on the timing capabilities of the +% system. See also convert_time/2. +% +% @deprecated Use stamp_date_time/3. + +convert_time(Stamp, Y, Mon, Day, Hour, Min, Sec, MilliSec) :- + stamp_date_time(Stamp, + date(Y, Mon, Day, + Hour, Min, FSec, + _, _, _), + local), + Sec is integer(float_integer_part(FSec)), + MilliSec is integer(float_fractional_part(FSec)*1000). compile_aux_clauses([]). compile_aux_clauses([(:- G)|Cls]) :- diff --git a/library/dialect/swi/fli/swi.c b/library/dialect/swi/fli/swi.c index b56e74a00..13086d5bb 100755 --- a/library/dialect/swi/fli/swi.c +++ b/library/dialect/swi/fli/swi.c @@ -2681,32 +2681,6 @@ PL_foreign_context_address(control_t ctx) } } -static int -SWI_ctime(void) -{ -#if HAVE_CTIME - time_t tim; -#endif - YAP_Term t1 = YAP_ARG1; - - if (YAP_IsVarTerm(t1)) { - YAP_Error(0,t1,"bad argumento to ctime"); - return FALSE; - } -#if HAVE_CTIME - if (YAP_IsIntTerm(t1)) - tim = (time_t)YAP_IntOfTerm(t1); - else if (YAP_IsFloatTerm(t1)) - tim = (time_t)YAP_FloatOfTerm(t1); - else - return FALSE; - return YAP_Unify(YAP_BufferToString(ctime(&tim)), YAP_ARG2); -#else - YAP_Error(0,0L,"convert_time requires ctime"); - return FALSE; -#endif -} - X_API int PL_get_signum_ex(term_t sig, int *n) { @@ -2805,7 +2779,6 @@ void Yap_swi_install(void) { Yap_install_blobs(); - YAP_UserCPredicate("ctime", SWI_ctime, 2); } int Yap_read_term(term_t t, IOSTREAM *st, term_t *excep, term_t vs);