melib/datetime: Set C locale for strptime parsing
This is the locale that should be used for computer interoperability when doing date and time parsing and formatting. Without this, on systems which don't have the US locale set, the parsing returns 0.jmap-eventsource
parent
829f1243fb
commit
f7cbd9a64d
|
@ -43,7 +43,7 @@ use std::ffi::{CStr, CString};
|
|||
|
||||
pub type UnixTimestamp = u64;
|
||||
|
||||
use libc::{timeval, timezone};
|
||||
use libc::{timeval, timezone, uselocale};
|
||||
|
||||
extern "C" {
|
||||
fn strptime(
|
||||
|
@ -214,7 +214,19 @@ where
|
|||
] {
|
||||
unsafe {
|
||||
let fmt = CStr::from_bytes_with_nul_unchecked(fmt);
|
||||
|
||||
let locale = ::libc::newlocale(
|
||||
::libc::LC_TIME,
|
||||
b"C\0".as_ptr() as *const i8,
|
||||
std::ptr::null_mut(),
|
||||
);
|
||||
|
||||
let old_locale = uselocale(locale);
|
||||
let ret = strptime(s.as_ptr(), fmt.as_ptr(), &mut new_tm as *mut _);
|
||||
uselocale(old_locale);
|
||||
|
||||
::libc::freelocale(locale);
|
||||
|
||||
if ret.is_null() {
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue