]> xenbits.xensource.com Git - xcp/xen-api-libs.git/commitdiff
Add function to Date module to assert ISO 8601 datetime values are UTC
authorRob Hoes <rob.hoes@citrix.com>
Tue, 12 Oct 2010 11:10:55 +0000 (12:10 +0100)
committerRob Hoes <rob.hoes@citrix.com>
Tue, 12 Oct 2010 11:10:55 +0000 (12:10 +0100)
Adds ocamldoc for the whole Date module as well.

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
stdext/date.ml
stdext/date.mli

index 71546b681e0dddd98cb75fc99455b44ccde2b58c..ea82a9d2239728bb939df029a6c86dd987f77084 100644 (file)
@@ -15,7 +15,6 @@
 type iso8601 = string
 type rfc822 = string
 
-(* Convert calendar time, x, to tm in UTC *)
 let of_float x = 
   let time = Unix.gmtime x in
   Printf.sprintf "%04d%02d%02dT%02d:%02d:%02dZ"
@@ -65,4 +64,9 @@ let to_float x =
 let to_string x = x
 let of_string x = x
 
+let assert_utc x =
+       try
+               Scanf.sscanf x "%_[0-9]T%_[0-9]:%_[0-9]:%_[0-9]Z" ()
+       with _ -> invalid_arg x
+
 let never = of_float 0.0
index f0d6650504239bea05801caa488ead9d6e68818f..79a1d2b273e3738a17063097ba75d2514e83dd8b 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Lesser General Public License for more details.
  *)
+(** Additional types and functions for dates *)
+
+(** {2 ISO 8601 Dates} *)
+
+(** An ISO-8601 date/time type. *)
 type iso8601
+
+(** Convert calendar time [x] (as returned by e.g. Unix.time), to time in UTC. *)
 val of_float : float -> iso8601
+
+(** Convert date/time to a float value: the number of seconds since 00:00:00 UTC, 1 Jan 1970. *)
 val to_float : iso8601 -> float
+
+(** Convert date/time to an ISO 8601 formatted string. *)
 val to_string : iso8601 -> string
+
+(** Convert ISO 8601 formatted string to a date/time value. *)
 val of_string : string -> iso8601
+
+(** Raises an Invalid_argument exception if the given date is not a UTC date.
+ *  A UTC date is an ISO 8601 strings that ends with the character 'Z'. *)
+val assert_utc : iso8601 -> unit
+
+(** Representation of the concept "never" (actually 00:00:00 UTC, 1 Jan 1970). *)
 val never: iso8601
 
+(** {2 RFC 822 Dates} *)
+
+(** An RFC 822 date/time type. *)
 type rfc822
+
+(** Convert calendar time [x] (as returned by e.g. Unix.time), to RFC 822. *)
 val rfc822_of_float : float -> rfc822
+
+(** Convert RFC 822 date/time to a formatted string. *)
 val rfc822_to_string : rfc822 -> string