Relation dates, with conversion condition upon it
git-svn-id: file:///srv/svn/repo/kosuzu/trunk@43 eb64cd80-c68d-6f47-b6a3-0ada418499da
This commit is contained in:
@@ -15,3 +15,8 @@ let now () = Unix.time () |> Unix.gmtime |>
|
||||
let to_secs date =
|
||||
Scanf.sscanf date "%4d-%02d-%02dT%02d:%02d:%02d"
|
||||
(fun y mo d h mi s -> (y-1970)*31557600 + mo*2629800 + d*86400 + h*3600 + mi*60 + s)
|
||||
let of_secs s =
|
||||
let { Unix.tm_sec=seconds; tm_min=minutes; tm_hour=hours;
|
||||
tm_mday=day; tm_mon=month; tm_year=year; _ } = Unix.localtime (float_of_int s) in
|
||||
Printf.sprintf "%4d-%02d-%02dT%02d:%02d:%02d"
|
||||
(year+1900) (month+1) day hours minutes seconds
|
||||
|
||||
@@ -84,7 +84,7 @@ let list filename = try
|
||||
let contains text = function
|
||||
| Msgpck.List (id::_time::title::_authors::_topics::[]) ->
|
||||
(match to_id id with
|
||||
| "" -> prerr_endline ("Invalid id for " ^ Msgpck.to_string title); false
|
||||
| "" -> Printf.eprintf "Invalid id for %s" (Msgpck.to_string title); false
|
||||
| id -> text.Text.id = id)
|
||||
| _ -> prerr_endline ("Invalid record pattern"); false
|
||||
|
||||
@@ -105,27 +105,29 @@ let txt_iter_apply fn i = function
|
||||
end with e -> prerr_endline "iter ref reps"; raise e
|
||||
in
|
||||
fn i id t title authors topics references replies
|
||||
| _ -> prerr_endline ("\n\nInvalid record structure\n\n")
|
||||
| x -> Printf.eprintf "Invalid record structure: %s\n%!" (Msgpck.show x)
|
||||
|
||||
let txt_fold_apply fn i m =
|
||||
(* Printf.eprintf "%s\n%!" @@ Msgpck.show m;*)
|
||||
match m with
|
||||
let txt_fold_apply fn i = function
|
||||
| Msgpck.List (id::time::title::authors::topics::extra) ->
|
||||
let t = match time with Msgpck.Int i -> Int32.of_int i | Msgpck.Uint32 i -> i
|
||||
| x -> Msgpck.to_uint32 x in
|
||||
let id = to_id id in
|
||||
let title = Msgpck.to_string title in
|
||||
let topics = try to_str_list topics with _e -> Printf.eprintf "topics %s" title; [] in
|
||||
let authors = try to_str_list authors with _e -> Printf.eprintf "authors %s" title; [] in
|
||||
let topics = to_str_list topics in
|
||||
let authors = to_str_list authors in
|
||||
let references, replies = begin match extra with
|
||||
| [] -> [], []
|
||||
| refs::[] -> (try to_str_list refs, [] with e -> prerr_endline "fold ref"; raise e)
|
||||
| refs::[] -> to_str_list refs, []
|
||||
| refs::replies::_xs -> to_str_list refs, to_str_list replies
|
||||
end
|
||||
in
|
||||
fn i id t title authors topics references replies
|
||||
| x -> Printf.eprintf "Invalid record structure: %s\n%!" (Msgpck.show x); i
|
||||
| x -> Printf.eprintf "Invalid record structure: %s\n%!" (Msgpck.show x); i
|
||||
|
||||
let iteri fn pack = List.iteri (txt_iter_apply fn) (Msgpck.to_list pack.texts)
|
||||
let fold fn init pack = List.fold_left (txt_fold_apply fn) init
|
||||
(try Msgpck.to_list pack.texts with e -> prerr_string "Pack.fold"; raise e)
|
||||
let iteri fn pack = List.iteri
|
||||
(txt_iter_apply fn)
|
||||
(Msgpck.to_list pack.texts)
|
||||
|
||||
let fold fn init pack = List.fold_left
|
||||
(fun acc m -> try txt_fold_apply fn acc m with Invalid_argument x -> prerr_endline x; acc) init
|
||||
(try Msgpck.to_list pack.texts with e -> prerr_string "Invalid pack.texts"; raise e)
|
||||
|
||||
Reference in New Issue
Block a user