Commit 7e1e8fa5 authored by Stephane Glondu's avatar Stephane Glondu

Move datetime datatype to web/

parent cb8d8152
......@@ -52,10 +52,3 @@ module Z : sig
val bit_length : t -> int
val of_bits : string -> t
end
type datetime
val now : unit -> datetime
val string_of_datetime : datetime -> string
val datetime_of_string : string -> datetime
val datetime_compare : datetime -> datetime -> int
val format_datetime : string -> datetime -> string
......@@ -25,7 +25,6 @@
type number <ocaml predef from="Serializable_builtin"> = abstract
type uuid <ocaml predef from="Serializable_builtin"> = abstract
type datetime <ocaml predef from="Serializable_builtin"> = abstract
(** {2 Basic cryptographic datastructures} *)
......
......@@ -71,28 +71,6 @@ let uuid_of_string x =
| `String s -> raw_uuid_of_string s
| _ -> invalid_arg "uuid_of_string: a string was expected"
(** {1 Serializers for type datetime} *)
let write_datetime buf n =
Bi_outbuf.add_char buf '"';
Bi_outbuf.add_string buf (Platform.string_of_datetime n);
Bi_outbuf.add_char buf '"'
let string_of_datetime ?(len=28) n =
let buf = Bi_outbuf.create len in
write_datetime buf n;
Bi_outbuf.contents buf
let datetime_of_json = function
| `String s -> Platform.datetime_of_string s
| _ -> invalid_arg "datetime_of_json: a string was expected"
let read_datetime state buf =
datetime_of_json (Yojson.Safe.from_lexbuf ~stream:true state buf)
let datetime_of_string s =
datetime_of_json (Yojson.Safe.from_string s)
(** {1 Serializers for type int_or_null} *)
let write_int_or_null buf = function
......
......@@ -35,13 +35,6 @@ val string_of_uuid : ?len:int -> uuid -> string
val read_uuid : Yojson.Safe.lexer_state -> Lexing.lexbuf -> uuid
val uuid_of_string : string -> uuid
(** {1 Serializers for type datetime} *)
val write_datetime : Bi_outbuf.t -> datetime -> unit
val string_of_datetime : ?len:int -> datetime -> string
val read_datetime : Yojson.Safe.lexer_state -> Lexing.lexbuf -> datetime
val datetime_of_string : string -> datetime
(** {1 Serializers for type int_or_null} *)
val write_int_or_null : Bi_outbuf.t -> int_or_null -> unit
......
......@@ -23,7 +23,6 @@ open Platform
type number = Z.t
type uuid = Uuidm.t
type datetime = Platform.datetime
type int_or_null = int option
module SSet = Set.Make(String)
......
......@@ -23,7 +23,6 @@ open Platform
type number = Z.t
type uuid = Uuidm.t
type datetime = Platform.datetime
type int_or_null = int option
module SSet : Set.S with type elt = string
......
......@@ -126,10 +126,3 @@ module Z = struct
else res
in loop zero (pred n)
end
type datetime
let now () = assert false
let string_of_datetime _ = assert false
let datetime_of_string _ = assert false
let datetime_compare _ _ = assert false
let format_datetime _ _ = assert false
......@@ -79,34 +79,3 @@ module Z = struct
let ( =% ) = equal
let bit_length x = Pervasives.(String.length (to_bits x) * 8)
end
open CalendarLib
let datetime_format = "%Y-%m-%d %H:%M:%S"
type datetime = Fcalendar.Precise.t * string option
let now () = CalendarLib.Fcalendar.Precise.now (), None
let string_of_datetime (n, s) =
match s with
| Some s -> s
| None ->
let n = Fcalendar.Precise.to_gmt n in
let a = Printer.Precise_Fcalendar.sprint datetime_format n in
let ts = Printf.sprintf "%.6f" (Fcalendar.Precise.to_unixfloat n) in
let i = String.index ts '.' in
let b = String.sub ts i (String.length ts - i) in
a ^ b
let datetime_of_string s =
let i = String.index s '.' in
let l = Printer.Precise_Fcalendar.from_fstring datetime_format (String.sub s 0 i) in
let l = Fcalendar.Precise.from_gmt l in
let r = float_of_string ("0" ^ String.sub s i (String.length s-i)) in
(Fcalendar.Precise.add l (Fcalendar.Precise.Period.second r), Some s)
let datetime_compare (a, _) (b, _) =
CalendarLib.Fcalendar.Precise.compare a b
let format_datetime fmt (a, _) =
CalendarLib.Printer.Precise_Fcalendar.sprint fmt a
......@@ -8,6 +8,8 @@ Group
Election
Credential
Web_serializable_builtin_t
Web_serializable_builtin_j
Web_serializable_j
Web_common
Web_persist
......
......@@ -22,9 +22,9 @@
open Lwt
open Platform
open Common
open Serializable_builtin_j
open Serializable_t
open Web_serializable_t
open Web_serializable_builtin_t
open Web_serializable_j
let spool_dir = ref "."
......
......@@ -24,7 +24,7 @@ open Platform
open Serializable_j
open Signatures
open Common
open Web_serializable_t
open Web_serializable_j
open Web_signatures
open Web_common
......
......@@ -24,8 +24,8 @@
(** {1 Predefined types} *)
type uuid <ocaml predef from="Serializable_builtin"> = abstract
type datetime <ocaml predef from="Serializable_builtin"> = abstract
type string_set <ocaml predef from="Serializable_builtin"> = abstract
type datetime <ocaml predef from="Web_serializable_builtin"> = abstract
(** {1 Web-specific types} *)
......
(**************************************************************************)
(* BELENIOS *)
(* *)
(* Copyright © 2012-2016 Inria *)
(* *)
(* This program is free software: you can redistribute it and/or modify *)
(* it under the terms of the GNU Affero General Public License as *)
(* published by the Free Software Foundation, either version 3 of the *)
(* License, or (at your option) any later version, with the additional *)
(* exemption that compiling, linking, and/or using OpenSSL is allowed. *)
(* *)
(* This program is distributed in the hope that it will be useful, but *)
(* WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)
(* Affero General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Affero General Public *)
(* License along with this program. If not, see *)
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Web_serializable_builtin_t
(** {1 Serializers for type datetime} *)
let write_datetime buf n =
Bi_outbuf.add_char buf '"';
Bi_outbuf.add_string buf (raw_string_of_datetime n);
Bi_outbuf.add_char buf '"'
let datetime_of_json = function
| `String s -> raw_datetime_of_string s
| _ -> invalid_arg "datetime_of_json: a string was expected"
let read_datetime state buf =
datetime_of_json (Yojson.Safe.from_lexbuf ~stream:true state buf)
(**************************************************************************)
(* BELENIOS *)
(* *)
(* Copyright © 2012-2016 Inria *)
(* *)
(* This program is free software: you can redistribute it and/or modify *)
(* it under the terms of the GNU Affero General Public License as *)
(* published by the Free Software Foundation, either version 3 of the *)
(* License, or (at your option) any later version, with the additional *)
(* exemption that compiling, linking, and/or using OpenSSL is allowed. *)
(* *)
(* This program is distributed in the hope that it will be useful, but *)
(* WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)
(* Affero General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Affero General Public *)
(* License along with this program. If not, see *)
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Web_serializable_builtin_t
(** {1 Serializers for type datetime} *)
val write_datetime : Bi_outbuf.t -> datetime -> unit
val read_datetime : Yojson.Safe.lexer_state -> Lexing.lexbuf -> datetime
(**************************************************************************)
(* BELENIOS *)
(* *)
(* Copyright © 2012-2016 Inria *)
(* *)
(* This program is free software: you can redistribute it and/or modify *)
(* it under the terms of the GNU Affero General Public License as *)
(* published by the Free Software Foundation, either version 3 of the *)
(* License, or (at your option) any later version, with the additional *)
(* exemption that compiling, linking, and/or using OpenSSL is allowed. *)
(* *)
(* This program is distributed in the hope that it will be useful, but *)
(* WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)
(* Affero General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Affero General Public *)
(* License along with this program. If not, see *)
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open CalendarLib
let datetime_format = "%Y-%m-%d %H:%M:%S"
type datetime = Fcalendar.Precise.t * string option
let now () = CalendarLib.Fcalendar.Precise.now (), None
let raw_string_of_datetime (n, s) =
match s with
| Some s -> s
| None ->
let n = Fcalendar.Precise.to_gmt n in
let a = Printer.Precise_Fcalendar.sprint datetime_format n in
let ts = Printf.sprintf "%.6f" (Fcalendar.Precise.to_unixfloat n) in
let i = String.index ts '.' in
let b = String.sub ts i (String.length ts - i) in
a ^ b
let raw_datetime_of_string s =
let i = String.index s '.' in
let l = Printer.Precise_Fcalendar.from_fstring datetime_format (String.sub s 0 i) in
let l = Fcalendar.Precise.from_gmt l in
let r = float_of_string ("0" ^ String.sub s i (String.length s-i)) in
(Fcalendar.Precise.add l (Fcalendar.Precise.Period.second r), Some s)
let datetime_compare (a, _) (b, _) =
CalendarLib.Fcalendar.Precise.compare a b
let format_datetime fmt (a, _) =
CalendarLib.Printer.Precise_Fcalendar.sprint fmt a
(**************************************************************************)
(* BELENIOS *)
(* *)
(* Copyright © 2012-2016 Inria *)
(* *)
(* This program is free software: you can redistribute it and/or modify *)
(* it under the terms of the GNU Affero General Public License as *)
(* published by the Free Software Foundation, either version 3 of the *)
(* License, or (at your option) any later version, with the additional *)
(* exemption that compiling, linking, and/or using OpenSSL is allowed. *)
(* *)
(* This program is distributed in the hope that it will be useful, but *)
(* WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)
(* Affero General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Affero General Public *)
(* License along with this program. If not, see *)
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
type datetime
val now : unit -> datetime
val raw_string_of_datetime : datetime -> string
val raw_datetime_of_string : string -> datetime
val datetime_compare : datetime -> datetime -> int
val format_datetime : string -> datetime -> string
......@@ -24,6 +24,7 @@ open Platform
open Serializable_j
open Signatures
open Common
open Web_serializable_builtin_t
open Web_serializable_j
open Web_common
open Web_services
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment