Changeset 43 in code for trunk/lib


Ignore:
Timestamp:
Dec 18, 2022, 2:49:25 PM (2 years ago)
Author:
fox
Message:

Relation dates, with conversion condition upon it

Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/date.ml

    r5 r43  
    1616        Scanf.sscanf date "%4d-%02d-%02dT%02d:%02d:%02d"
    1717                (fun y mo d h mi s -> (y-1970)*31557600 + mo*2629800 + d*86400 + h*3600 + mi*60 + s)
     18let of_secs s =
     19        let { Unix.tm_sec=seconds; tm_min=minutes; tm_hour=hours;
     20                tm_mday=day; tm_mon=month; tm_year=year; _ } = Unix.localtime (float_of_int s) in
     21                Printf.sprintf "%4d-%02d-%02dT%02d:%02d:%02d"
     22                        (year+1900) (month+1) day hours minutes seconds
  • trunk/lib/header_pack.ml

    r42 r43  
    8585        | Msgpck.List (id::_time::title::_authors::_topics::[]) ->
    8686                (match to_id id with
    87                  | "" -> prerr_endline ("Invalid id for " ^ Msgpck.to_string title); false
     87                 | "" -> Printf.eprintf "Invalid id for %s" (Msgpck.to_string title); false
    8888                 | id -> text.Text.id = id)
    8989        | _ -> prerr_endline ("Invalid record pattern"); false
     
    106106                in
    107107                fn i id t title authors topics references replies
    108         | _  -> prerr_endline ("\n\nInvalid record structure\n\n")
     108        | x -> Printf.eprintf "Invalid record structure: %s\n%!" (Msgpck.show x)
    109109
    110 let txt_fold_apply fn i m =
    111 (*      Printf.eprintf "%s\n%!" @@ Msgpck.show m;*)
    112         match m with
     110let txt_fold_apply fn i = function
    113111        | Msgpck.List (id::time::title::authors::topics::extra) ->
    114112                let t = match time with Msgpck.Int i -> Int32.of_int i | Msgpck.Uint32 i -> i
     
    116114                let id = to_id id in
    117115                let title = Msgpck.to_string title in
    118                 let topics = try to_str_list topics with _e -> Printf.eprintf "topics %s" title; [] in
    119                 let authors = try to_str_list authors with _e -> Printf.eprintf "authors %s" title; [] in
     116                let topics = to_str_list topics in
     117                let authors = to_str_list authors in
    120118                let references, replies = begin match extra with
    121119                        | [] -> [], []
    122                         | refs::[] -> (try to_str_list refs, [] with e -> prerr_endline "fold ref"; raise e)
     120                        | refs::[] -> to_str_list refs, []
    123121                        | refs::replies::_xs -> to_str_list refs, to_str_list replies
    124122                        end
    125123                in
    126124                fn i id t title authors topics references replies
    127         | x  -> Printf.eprintf "Invalid record structure: %s\n%!" (Msgpck.show x); i
     125        | x -> Printf.eprintf "Invalid record structure: %s\n%!" (Msgpck.show x); i
    128126
    129 let iteri fn pack = List.iteri (txt_iter_apply fn) (Msgpck.to_list pack.texts)
    130 let fold fn init pack = List.fold_left (txt_fold_apply fn) init
    131         (try Msgpck.to_list pack.texts with e -> prerr_string "Pack.fold"; raise e)
     127let iteri fn pack = List.iteri
     128        (txt_iter_apply fn)
     129        (Msgpck.to_list pack.texts)
     130
     131let fold fn init pack = List.fold_left
     132        (fun acc m -> try txt_fold_apply fn acc m with Invalid_argument x -> prerr_endline x; acc) init
     133        (try Msgpck.to_list pack.texts with e -> prerr_string "Invalid pack.texts"; raise e)
Note: See TracChangeset for help on using the changeset viewer.