changeset 2187:14c45a0b6362

Basis.fromMilliseconds
author Adam Chlipala <adam@chlipala.net>
date Sun, 01 Nov 2015 11:55:01 -0500
parents d87d72b6e299
children 61866c765485
files include/urweb/urweb_cpp.h lib/js/urweb.js lib/ur/basis.urs src/c/urweb.c src/settings.sml
diffstat 5 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/include/urweb/urweb_cpp.h	Sat Oct 31 19:21:05 2015 -0400
+++ b/include/urweb/urweb_cpp.h	Sun Nov 01 11:55:01 2015 -0500
@@ -273,6 +273,7 @@
 uw_Basis_int uw_Basis_toSeconds(struct uw_context *, uw_Basis_time);
 uw_Basis_int uw_Basis_diffInMilliseconds(struct uw_context *, uw_Basis_time, uw_Basis_time);
 uw_Basis_int uw_Basis_toMilliseconds(struct uw_context *, uw_Basis_time);
+uw_Basis_time uw_Basis_fromMilliseconds(struct uw_context *, uw_Basis_int);
 uw_Basis_time uw_Basis_fromDatetime(struct uw_context *, uw_Basis_int, uw_Basis_int, uw_Basis_int, uw_Basis_int, uw_Basis_int, uw_Basis_int);
 uw_Basis_int uw_Basis_datetimeYear(struct uw_context *, uw_Basis_time);
 uw_Basis_int uw_Basis_datetimeMonth(struct uw_context *, uw_Basis_time);
--- a/lib/js/urweb.js	Sat Oct 31 19:21:05 2015 -0400
+++ b/lib/js/urweb.js	Sun Nov 01 11:55:01 2015 -0500
@@ -149,6 +149,10 @@
     return Math.round(tm / 1000);
 }
 
+function fromMilliseconds(tm) {
+    return tm * 1000;
+}
+
 function addSeconds(tm, n) {
     return tm + n * 1000000;
 }
--- a/lib/ur/basis.urs	Sat Oct 31 19:21:05 2015 -0400
+++ b/lib/ur/basis.urs	Sun Nov 01 11:55:01 2015 -0500
@@ -163,6 +163,7 @@
 val diffInSeconds : time -> time -> int
 (* Earlier time first *)
 val toMilliseconds : time -> int
+val fromMilliseconds : int -> time
 val diffInMilliseconds : time -> time -> int
 val timef : string -> time -> string (* Uses strftime() format string *)
 val readUtc : string -> option time
--- a/src/c/urweb.c	Sat Oct 31 19:21:05 2015 -0400
+++ b/src/c/urweb.c	Sun Nov 01 11:55:01 2015 -0500
@@ -4060,6 +4060,11 @@
   return tm.seconds * 1000 + tm.microseconds / 1000;
 }
 
+uw_Basis_time uw_Basis_fromMilliseconds(uw_context ctx, uw_Basis_int n) {
+  uw_Basis_time tm = {n / 1000, n % 1000 * 1000};
+  return tm;
+}
+
 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);
 }
--- a/src/settings.sml	Sat Oct 31 19:21:05 2015 -0400
+++ b/src/settings.sml	Sun Nov 01 11:55:01 2015 -0500
@@ -342,6 +342,7 @@
                           ("addSeconds", "addSeconds"),
                           ("diffInSeconds", "diffInSeconds"),
                           ("toMilliseconds", "toMilliseconds"),
+                          ("fromMilliseconds", "fromMilliseconds"),
                           ("diffInMilliseconds", "diffInMilliseconds"),
 
                           ("fromDatetime", "fromDatetime"),