Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/branches/rt-transition/system/Basis/Implementation/date.sml
ViewVC logotype

Diff of /sml/branches/rt-transition/system/Basis/Implementation/date.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2845, Wed Nov 7 22:41:52 2007 UTC revision 2846, Wed Nov 7 23:05:09 2007 UTC
# Line 102  Line 102 
102      fun isDst (DATE{isDst, ...}) = isDst      fun isDst (DATE{isDst, ...}) = isDst
103      fun offset (DATE{offset,...}) = offset      fun offset (DATE{offset,...}) = offset
104    
105    (* takes two tm's and returns the second tm with    (* functionally updates a tm's dst flag.
    * its dst flag set to the first one's.  
106     * Used to compute local offsets     * Used to compute local offsets
107     *)     *)
108      fun withDst dst (tm2 : tm) : tm=      fun withDst dst (tm : tm) : tm = {
109            (#1 tm2, #2 tm2, #3 tm2, #4 tm2, #5 tm2, #6 tm2, #7 tm2, #8 tm2, dst)              tm_sec = #tm_sec tm,
110                tm_min = #tm_min tm,
111                tm_hour = #tm_hour tm,
112                tm_mday = #tm_mday tm,
113                tm_mon = #tm_mon tm,
114                tm_year = #tm_year tm,
115                tm_wday = #tm_wday tm,
116                tm_yday = #tm_yday tm,
117                tm_isdst = dst
118              }
119    
120      fun dstOf (tm : tm) = #9 tm      fun dstOf (tm : tm) = #tm_isdst tm
121    
122      fun localOffset' () = let      fun localOffset' () = let
123            val t = Int32.fromLarge (Time.toSeconds (Time.now ()))            val t = Time.now()
124            val t_as_utc_tm = gmTime' t            val t_as_utc_tm = gmTime t
125            val t_as_loc_tm = localTime' t            val t_as_loc_tm = localTime t
126            val loc_dst = dstOf t_as_loc_tm            val loc_dst = dstOf t_as_loc_tm
127            val t_as_utc_tm' = withDst loc_dst t_as_utc_tm            val t_as_utc_tm' = withDst loc_dst t_as_utc_tm
128            val t' = mkTime' t_as_utc_tm'            val t' = mkTime' t_as_utc_tm'
           val time = Time.fromSeconds o Int32.toLarge  
129            in            in
130              (Time.- (time t', time t), loc_dst)              (Time.- (Time.fromTime_t t', t), loc_dst)
131            end            end
132    
133      val localOffset = #1 o localOffset'      val localOffset = #1 o localOffset'
# Line 200  Line 207 
207                }                }
208            end            end
209    
210      fun toTM d = let      fun toTM (DATE d) = {
211            val (DATE d) = canonicalizeDate d              tm_sec = #second d,
212            in (              tm_min = #minute d,
213              #second d,                  (* tm_sec *)              tm_hour = #hour d,
214              #minute d,                  (* tm_min *)              tm_mday = #day d,
215              #hour d,                    (* tm_hour *)              tm_mon = monthToInt(#month d),
216              #day d,                     (* tm_mday *)              tm_year = #year d - baseYear,
217              monthToInt(#month d),       (* tm_mon *)              tm_wday = dayToInt(#wday d),
218              #year d - baseYear,         (* tm_year *)              tm_yday = #yday d,
219              dayToInt(#wday d),          (* tm_wday *)              tm_isdst = case (#isDst d)
             #yday d,                    (* tm_yday *)  
             case (#isDst d)             (* tm_isdst *)  
220               of NONE => ~1               of NONE => ~1
221                | (SOME false) => 0                | (SOME false) => 0
222                | (SOME true) => 1                | (SOME true) => 1
223              (* end case *)            }
           ) end  
224    
225      fun fromTM (tm_sec, tm_min, tm_hour, tm_mday, tm_mon,      fun fromTM {tm_sec, tm_min, tm_hour, tm_mday, tm_mon,
226                  tm_year, tm_wday, tm_yday, tm_isdst) offset =                  tm_year, tm_wday, tm_yday, tm_isdst} offset =
227            DATE{            DATE{
228                year = baseYear + tm_year,                year = baseYear + tm_year,
229                month = InlineT.PolyVector.sub (monthTbl, tm_mon),                month = InlineT.PolyVector.sub (monthTbl, tm_mon),
# Line 233  Line 237 
237                offset = offset                offset = offset
238              }              }
239    
   
240      fun fromTimeLocal t = fromTM (localTime t) NONE      fun fromTimeLocal t = fromTM (localTime t) NONE
241    
242      fun fromTimeUniv t = fromTM (gmTime t) (SOME Time.zeroTime)      fun fromTimeUniv t = fromTM (gmTime t) (SOME Time.zeroTime)

Legend:
Removed from v.2845  
changed lines
  Added in v.2846

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0