Mercurial > urweb
changeset 1973:155bd0bc4d28
Day of week functions.
author | Patrick Hurst <phurst@mit.edu> |
---|---|
date | Thu, 05 Dec 2013 11:36:54 -0500 |
parents | 56c68443cb9d |
children | a10368c65e7f |
files | lib/ur/basis.urs lib/ur/datetime.ur lib/ur/datetime.urs src/c/urweb.c |
diffstat | 4 files changed, 23 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/ur/basis.urs Thu Dec 05 11:36:46 2013 -0500 +++ b/lib/ur/basis.urs Thu Dec 05 11:36:54 2013 -0500 @@ -175,6 +175,7 @@ val datetimeHour : time -> int val datetimeMinute: time -> int val datetimeSecond : time -> int +val datetimeDayOfWeek : time -> int (** * Encryption *)
--- a/lib/ur/datetime.ur Thu Dec 05 11:36:46 2013 -0500 +++ b/lib/ur/datetime.ur Thu Dec 05 11:36:54 2013 -0500 @@ -7,6 +7,18 @@ Second : int } +datatype day_of_week = Sunday | Monday | Tuesday | Wednesday | Thursday | + Friday | Saturday + +val show = mkShow (fn dow => case dow of + Sunday => "Sunday" + | Monday => "Monday" + | Tuesday => "Tuesday" + | Wednesday => "Wednesday" + | Thursday => "Thursday" + | Friday => "Friday" + | Saturday => "Saturday") + fun toTime dt : time = fromDatetime dt.Year dt.Month dt.Day dt.Hour dt.Minute dt.Second
--- a/lib/ur/datetime.urs Thu Dec 05 11:36:46 2013 -0500 +++ b/lib/ur/datetime.urs Thu Dec 05 11:36:54 2013 -0500 @@ -6,6 +6,11 @@ Second : int } +datatype day_of_week = Sunday | Monday | Tuesday | Wednesday | Thursday | + Friday | Saturday + +val show : show day_of_week + val toTime : datetime -> time val fromTime : time -> datetime val datetimef : string -> datetime -> string
--- a/src/c/urweb.c Thu Dec 05 11:36:46 2013 -0500 +++ b/src/c/urweb.c Thu Dec 05 11:36:54 2013 -0500 @@ -3894,6 +3894,11 @@ return tm.tm_sec; } +uw_Basis_int uw_Basis_datetimeDayOfWeek(uw_context ctx, uw_Basis_time time) { + struct tm tm; + gmtime_r(&time.seconds, &tm); + return tm.tm_wday; +} void *uw_get_global(uw_context ctx, char *name) {