# HG changeset patch # User Adam Chlipala # Date 1328371266 18000 # Node ID 225b87d4a7df9fe6d8cde6ed8ef07c6b09f3e682 # Parent 9dd8d47c3e58d7e21c5d150c349e7830045a22fb Basis.toMilliseconds and diffInMilliseconds, based on a patch from Gergely Buday diff -r 9dd8d47c3e58 -r 225b87d4a7df include/urweb.h --- a/include/urweb.h Sat Feb 04 10:42:18 2012 -0500 +++ b/include/urweb.h Sat Feb 04 11:01:06 2012 -0500 @@ -256,6 +256,8 @@ uw_Basis_time uw_Basis_addSeconds(uw_context, uw_Basis_time, uw_Basis_int); uw_Basis_int uw_Basis_diffInSeconds(uw_context, uw_Basis_time, uw_Basis_time); uw_Basis_int uw_Basis_toSeconds(uw_context, uw_Basis_time); +uw_Basis_int uw_Basis_diffInMilliseconds(uw_context, uw_Basis_time, uw_Basis_time); +uw_Basis_int uw_Basis_toMilliseconds(uw_context, uw_Basis_time); extern const uw_Basis_time uw_Basis_minTime; void uw_register_transactional(uw_context, void *data, uw_callback commit, uw_callback rollback, uw_callback_with_retry free); diff -r 9dd8d47c3e58 -r 225b87d4a7df lib/js/urweb.js --- a/lib/js/urweb.js Sat Feb 04 10:42:18 2012 -0500 +++ b/lib/js/urweb.js Sat Feb 04 11:01:06 2012 -0500 @@ -132,10 +132,18 @@ return Math.round((tm2 - tm1) / 1000000); } +function diffInMilliseconds(tm1, tm2) { + return Math.round((tm2 - tm1) / 1000); +} + function toSeconds(tm) { return Math.round(tm / 1000000); } +function toMilliseconds(tm) { + return Math.round(tm / 1000); +} + function addSeconds(tm, n) { return tm + n * 1000000; } diff -r 9dd8d47c3e58 -r 225b87d4a7df lib/ur/basis.urs --- a/lib/ur/basis.urs Sat Feb 04 10:42:18 2012 -0500 +++ b/lib/ur/basis.urs Sat Feb 04 11:01:06 2012 -0500 @@ -161,6 +161,8 @@ val toSeconds : time -> int val diffInSeconds : time -> time -> int (* Earlier time first *) +val toMilliseconds : time -> int +val diffInMilliseconds : time -> time -> int val timef : string -> time -> string (* Uses strftime() format string *) val readUtc : string -> option time diff -r 9dd8d47c3e58 -r 225b87d4a7df src/c/urweb.c --- a/src/c/urweb.c Sat Feb 04 10:42:18 2012 -0500 +++ b/src/c/urweb.c Sat Feb 04 11:01:06 2012 -0500 @@ -3681,6 +3681,14 @@ return difftime(tm2.seconds, tm1.seconds); } +uw_Basis_int uw_Basis_toMilliseconds(uw_context ctx, uw_Basis_time tm) { + return tm.seconds * 1000 + tm.microseconds / 1000; +} + +uw_Basis_int uw_Basis_diffInMilliseconds(uw_context ctx, uw_Basis_time tm1, uw_Basis_time tm2) { + return uw_Basis_toMilliseconds(ctx, tm2) - uw_Basis_toMilliseconds(ctx, tm1); +} + uw_Basis_int uw_Basis_toSeconds(uw_context ctx, uw_Basis_time tm) { return tm.seconds; } diff -r 9dd8d47c3e58 -r 225b87d4a7df src/settings.sml --- a/src/settings.sml Sat Feb 04 10:42:18 2012 -0500 +++ b/src/settings.sml Sat Feb 04 11:01:06 2012 -0500 @@ -286,6 +286,8 @@ ("toSeconds", "toSeconds"), ("addSeconds", "addSeconds"), ("diffInSeconds", "diffInSeconds"), + ("toMilliseconds", "toMilliseconds"), + ("diffInMilliseconds", "diffInMilliseconds"), ("onClick", "uw_onClick"), ("onDblclick", "uw_onDblclick"), diff -r 9dd8d47c3e58 -r 225b87d4a7df tests/millis.ur --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/millis.ur Sat Feb 04 11:01:06 2012 -0500 @@ -0,0 +1,17 @@ +fun diffThem tm = + tm' <- now; + return + Diff: {[diffInMilliseconds tm tm']} + + +fun main () : transaction page = + tm <- now; + + return + Now: {[toMilliseconds tm]}
+ Diff
+ +