This commit is contained in:
John Whitington 2020-12-02 14:06:17 +00:00
parent 0a9596f979
commit 389d9fedc3
1 changed files with 46 additions and 43 deletions

View File

@ -128,21 +128,23 @@ let return_date () =
_tm_wday = get_int 20 1; _tm_wday = get_int 20 1;
_tm_yday = get_int 22 3 - 1; _tm_yday = get_int 22 3 - 1;
_tm_isdst = false} _tm_isdst = false}
| _ -> | "Windows" | "Cygwin" ->
(* Run 'wmic os get LocalDateTime' (exists on XP Pro or later, Vista or later). *) (* Run 'wmic os get LocalDateTime' (exists on XP Pro or later, Vista or later). *)
let get_int r o l = int_of_string (String.sub r o l) in let get_int r o l = int_of_string (String.sub r o l) in
let tempfile = Filename.temp_file "cpdf" "strftime" in let tempfile = Filename.temp_file "cpdf" "strftime" in
let command = Filename.quote_command "wmic.exe" ~stdout:tempfile ["os"; "get"; "LocalDateTime"] in let command = Filename.quote_command "wmic.exe" ~stdout:tempfile ["os"; "get"; "LocalDateTime"] in
let outcode = Sys.command command in let outcode = Sys.command command in
if outcode > 0 then raise (Failure "wmic os get LocalDateTime command returned non-zero exit code") else if outcode > 0 then raise (Failure "wmic.exe os get LocalDateTime command returned non-zero exit code") else
let r = contents_of_file tempfile in let r = contents_of_file tempfile in
Sys.remove tempfile;
let r = utf8_of_utf16le r in let r = utf8_of_utf16le r in
(* Run 'wmic path win32_localtime get dayofweek' (exists on XP Pro or later, Vista or later). *) (* Run 'wmic path win32_localtime get dayofweek' (exists on XP Pro or later, Vista or later). *)
let tempfile = Filename.temp_file "cpdf" "strftime" in let tempfile = Filename.temp_file "cpdf" "strftime" in
let command = Filename.quote_command "wmic.exe" ~stdout:tempfile ["path"; "win32_localtime"; "get"; "dayofweek"] in let command = Filename.quote_command "wmic.exe" ~stdout:tempfile ["path"; "win32_localtime"; "get"; "dayofweek"] in
let outcode = Sys.command command in let outcode = Sys.command command in
if outcode > 0 then raise (Failure "wmic os get LocalDateTime command returned non-zero exit code") else if outcode > 0 then raise (Failure "wmic.exe path win32_localtime get dayofweek returned non-zero exit code") else
let r2 = contents_of_file tempfile in let r2 = contents_of_file tempfile in
Sys.remove tempfile;
let r2 = utf8_of_utf16le r2 in let r2 = utf8_of_utf16le r2 in
{_tm_sec = get_int r 41 2; {_tm_sec = get_int r 41 2;
_tm_min = get_int r 39 2; _tm_min = get_int r 39 2;
@ -153,6 +155,7 @@ let return_date () =
_tm_wday = get_int r2 13 1; _tm_wday = get_int r2 13 1;
_tm_yday = 0; (* FIXME Must calculate from DD MM YYYY using standard formulae *) _tm_yday = 0; (* FIXME Must calculate from DD MM YYYY using standard formulae *)
_tm_isdst = false} _tm_isdst = false}
| _ -> failwith "Unknown Sys.os_type in Cpdfstrftime.return_date"
let current_time () = let current_time () =
try return_date () with try return_date () with