summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Patrick Hurst <phurst@mit.edu>2013-12-05 11:36:46 -0500
committerGravatar Patrick Hurst <phurst@mit.edu>2013-12-05 11:36:46 -0500
commit5892c59cc4dd947692ff1503b39ab7dc4e02037b (patch)
tree9e31f41a597508da5950b1f4869d8ca7acc864e0
parent8492b32b68c817deb9556e377b0a1b7fbdef22bf (diff)
Basic datetime library.
-rw-r--r--Makefile.am13
-rw-r--r--lib/ur/datetime.ur26
-rw-r--r--lib/ur/datetime.urs12
3 files changed, 44 insertions, 7 deletions
diff --git a/Makefile.am b/Makefile.am
index d626c267..652296ea 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -95,13 +95,12 @@ if USE_EMACS
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
diff --git a/lib/ur/datetime.ur b/lib/ur/datetime.ur
new file mode 100644
index 00000000..56c29724
--- /dev/null
+++ b/lib/ur/datetime.ur
@@ -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)
diff --git a/lib/ur/datetime.urs b/lib/ur/datetime.urs
new file mode 100644
index 00000000..9d99b9e3
--- /dev/null
+++ b/lib/ur/datetime.urs
@@ -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