changeset 1972:56c68443cb9d

Basic datetime library.
author Patrick Hurst <phurst@mit.edu>
date Thu, 05 Dec 2013 11:36:46 -0500
parents 1e360ea06a09
children 155bd0bc4d28
files Makefile.am lib/ur/datetime.ur lib/ur/datetime.urs
diffstat 3 files changed, 44 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.am	Thu Dec 05 11:36:06 2013 -0500
+++ b/Makefile.am	Thu Dec 05 11:36:46 2013 -0500
@@ -95,13 +95,12 @@
 endif
 
 uninstall-local-main:
-	rm -f $(DESTDIR)$(BIN)/urweb \
-		$(DESTDIR)$(LIB_UR)/basis.urs $(DESTDIR)$(LIB_UR)/char.urs $(DESTDIR)$(LIB_UR)/listPair.urs $(DESTDIR)$(LIB_UR)/list.urs \
-		$(DESTDIR)$(LIB_UR)/monad.urs $(DESTDIR)$(LIB_UR)/option.urs $(DESTDIR)$(LIB_UR)/string.urs $(DESTDIR)$(LIB_UR)/top.urs \
-		$(DESTDIR)$(LIB_UR)/char.ur $(DESTDIR)$(LIB_UR)/listPair.ur $(DESTDIR)$(LIB_UR)/list.ur \
-		$(DESTDIR)$(LIB_UR)/monad.ur $(DESTDIR)$(LIB_UR)/option.ur $(DESTDIR)$(LIB_UR)/string.ur $(DESTDIR)$(LIB_UR)/top.ur \
-		$(DESTDIR)$(LIB_JS)/urweb.js \
-		$(DESTDIR)$(INCLUDE)/config.h $(DESTDIR)$(INCLUDE)/queue.h $(DESTDIR)$(INCLUDE)/request.h $(DESTDIR)$(INCLUDE)/types.h \
+	rm -f $(DESTDIR)$(BIN)/urweb $(DESTDIR)$(LIB_UR)/basis.urs $(DESTDIR)$(LIB_UR)/char.urs $(DESTDIR)$(LIB_UR)/datetime.urs		\
+		$(DESTDIR)$(LIB_UR)/listPair.urs \ $(DESTDIR)$(LIB_UR)/list.urs $(DESTDIR)$(LIB_UR)/monad.urs					\
+		$(DESTDIR)$(LIB_UR)/option.urs $(DESTDIR)$(LIB_UR)/string.urs $(DESTDIR)$(LIB_UR)/top.urs $(DESTDIR)$(LIB_UR)/char.ur		\
+		$(DESTDIR)$(LIB_UR)/datetime.ur $(DESTDIR)$(LIB_UR)/listPair.ur $(DESTDIR)$(LIB_UR)/list.ur $(DESTDIR)$(LIB_UR)/monad.ur	\
+		$(DESTDIR)$(LIB_UR)/option.ur $(DESTDIR)$(LIB_UR)/string.ur $(DESTDIR)$(LIB_UR)/top.ur $(DESTDIR)$(LIB_JS)/urweb.js		\
+		$(DESTDIR)$(INCLUDE)/config.h $(DESTDIR)$(INCLUDE)/queue.h $(DESTDIR)$(INCLUDE)/request.h $(DESTDIR)$(INCLUDE)/types.h		\
 		$(DESTDIR)$(INCLUDE)/urweb.h $(DESTDIR)$(INCLUDE)/types_cpp.h $(DESTDIR)$(INCLUDE)/urweb_cpp.h
 
 uninstall-local: uninstall-local-main uninstall-emacs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/ur/datetime.ur	Thu Dec 05 11:36:46 2013 -0500
@@ -0,0 +1,26 @@
+type datetime = {
+     Year : int,
+     Month : int,
+     Day : int,
+     Hour : int,
+     Minute : int,
+     Second : int
+}
+
+fun toTime dt : time = fromDatetime dt.Year dt.Month dt.Day
+                                    dt.Hour dt.Minute dt.Second
+
+fun fromTime t : datetime = {
+    Year = datetimeYear t,
+    Month = datetimeMonth t,
+    Day = datetimeDay t,
+    Hour = datetimeHour t,
+    Minute = datetimeMinute t,
+    Second = datetimeSecond t
+}
+
+fun datetimef fmt dt : string = timef fmt (toTime dt)
+
+val now : transaction datetime =
+    n <- now;
+    return (fromTime n)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/ur/datetime.urs	Thu Dec 05 11:36:46 2013 -0500
@@ -0,0 +1,12 @@
+type datetime = { Year : int,
+                  Month : int,
+                  Day : int,
+                  Hour : int,
+                  Minute : int,
+                  Second : int
+                }
+
+val toTime : datetime -> time
+val fromTime : time -> datetime
+val datetimef : string -> datetime -> string
+val now : transaction datetime