# HG changeset patch # User Adam Chlipala # Date 1297201949 18000 # Node ID 377c11586999e5d6fc7c653e3933efa019675e42 # Parent 8cab48efaff250823ec008064ba3b8a586ca636b Fully-functional Datebox diff -r 8cab48efaff2 -r 377c11586999 datebox.ur --- a/datebox.ur Tue Feb 08 16:06:31 2011 -0500 +++ b/datebox.ur Tue Feb 08 16:52:29 2011 -0500 @@ -5,14 +5,18 @@ style weekday style curday style otherday +style selday datatype month = Prev | This | Next +type date = {Year : int, Month : int, Day : int} + type t = {Month : source {ThisMonth : int, Year : int, ThisMonthLength : int, PrevMonthLength : int, MondayMonth : month, MondayDay : int, PrevMonthName : string, ThisMonthName : string, NextMonthName : string}, - Day : source int} + Day : source date, + Hide : source bool} fun pad len n = let @@ -84,95 +88,116 @@ fun monthInfo this = return (monthInfo' this) -val create = - tm <- now; +fun create tm = year <- return (readError (timef "%Y" tm)); month <- return (readError (timef "%m" tm)); - month <- source (monthInfo' {Month = month, Year = year}); + minf <- source (monthInfo' {Month = month, Year = year}); day <- return (readError (timef "%d" tm)); - day <- source day; - return {Month = month, Day = day} + day <- source {Year = year, Month = month, Day = day}; + hide <- source True; + return {Month = minf, Day = day, Hide = hide} -fun render (t : t) = - = 7 then - - else - - curday - | _ => otherday}>{[day]} - {let - val (month, day) = - case month of - Prev => if day = minf.PrevMonthLength then - (This, 1) - else - (Prev, day+1) - | This => if day = minf.ThisMonthLength then - (Next, 1) - else - (This, day+1) - | Next => (Next, day+1) - in - row month day (weekday+1) - end} - +fun render' t = + minf <- signal t.Month; + let + fun rows year month day = + let + fun row year month day weekday = + if weekday >= 7 then + + else + + if minf.ThisMonth = 1 then 12 else minf.ThisMonth - 1 + | This => minf.ThisMonth + | Next => if minf.ThisMonth = 12 then 1 else minf.ThisMonth + 1, + Day = day} + in + cday <- signal t.Day; + return (if Record.equal thisDate cday then + {[day]} + else case month of + This => {[day]} + | _ => {[day]}) + end}/> + {let + val (year, month, day) = + case month of + Prev => if day = minf.PrevMonthLength then + (if minf.ThisMonth = 1 then year + 1 else year, This, 1) + else + (year, Prev, day+1) + | This => if day = minf.ThisMonthLength then + (if minf.ThisMonth = 12 then year + 1 else year, Next, 1) + else + (year, This, day+1) + | Next => (year, Next, day+1) + in + row year month day (weekday+1) + end} + + in + case month of + Next => + | _ => + + {row year month day 0} + {let + val next = + case month of + Prev => Some (if minf.ThisMonth = 1 then year + 1 else year, This, day + 7 - minf.PrevMonthLength) + | This => + Some (if day + 7 > minf.ThisMonthLength then + (if minf.ThisMonth = 12 then year + 1 else year, Next, day + 7 - minf.ThisMonthLength) + else + (year, This, day + 7)) + | Next => None in - case month of - Next => - | _ => - - {row month day 0} - {let - val next = - case month of - Prev => Some (This, day + 7 - minf.PrevMonthLength) - | This => - Some (if day + 7 > minf.ThisMonthLength then - (Next, day + 7 - minf.ThisMonthLength) - else - (This, day + 7)) - | Next => None - in - case next of - None => - | Some (month, day) => rows month day - end} - - end - in - return - - - - - - - - {rows minf.MondayMonth minf.MondayDay} -
<< {[minf.PrevMonthName]}{[minf.ThisMonthName]} {[minf.Year]}{[minf.NextMonthName]} >>
M Tu W Th F Sa Su
-
- end}/> -
+ case next of + None => + | Some (year, month, day) => rows year month day + end} + + end + in + return + + + + + + + + {rows (if minf.ThisMonth = 1 && (case minf.MondayMonth of This => False | _ => True) then + minf.Year - 1 + else + minf.Year) minf.MondayMonth minf.MondayDay} +
<< {[minf.PrevMonthName]}{[minf.ThisMonthName]} {[minf.Year]}{[minf.NextMonthName]} >>
M Tu W Th F Sa Su
+
+ end -fun value t = - month <- signal t.Month; - day <- signal t.Day; - return {Year = month.Year, Month = month.ThisMonth, Day = day} +fun render t = + {[date.Year]}-{[date.Month]}-{[date.Day]}}/> +