Skip to content

Commit

Permalink
Update to time 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto committed Aug 7, 2023
1 parent 8cf3e13 commit a4fad50
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 323 deletions.
171 changes: 9 additions & 162 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/emscripten/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ byteorder = "1.3"
lazy_static = "1.4"
libc = "^0.2"
log = "0.4"
time = { version = "0.2", features = ["std"] }
time = { version = "0.3", features = ["std", "formatting"] }
wasmer = { path = "../api", version = "=4.1.1", default-features = false }
wasmer-types = { path = "../types", version = "=4.1.1" }

Expand Down
27 changes: 16 additions & 11 deletions lib/emscripten/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ pub fn _localtime(mut ctx: FunctionEnvMut<EmEnv>, time_p: u32) -> c_int {
let timespec = unsafe {
let time_p_addr = emscripten_memory_pointer!(memory.view(&ctx), time_p) as *mut i64;
let seconds = *time_p_addr;
time::OffsetDateTime::from_unix_timestamp(seconds)
time::OffsetDateTime::from_unix_timestamp(seconds).unwrap()
};

unsafe {
Expand Down Expand Up @@ -285,7 +285,7 @@ pub fn _localtime_r(ctx: FunctionEnvMut<EmEnv>, time_p: u32, result: u32) -> c_i
let memory = ctx.data().memory(0);
unsafe {
let seconds = emscripten_memory_pointer!(memory.view(&ctx), time_p) as *const i32;
let timespec = time::OffsetDateTime::from_unix_timestamp_nanos(*seconds as _);
let timespec = time::OffsetDateTime::from_unix_timestamp_nanos(*seconds as _).unwrap();

// debug!(
// ">>>>>>> time = {}, {}, {}, {}, {}, {}, {}, {}",
Expand Down Expand Up @@ -419,18 +419,23 @@ pub fn _strftime(

let tm = unsafe { &*tm };

let rust_date = time::Date::try_from_ymd(tm.tm_year, tm.tm_mon as u8, tm.tm_mday as u8);
if rust_date.is_err() {
let Ok(rust_date) = time::Date::from_calendar_date(
tm.tm_year,
time::Month::try_from(tm.tm_mon as u8).unwrap(),
tm.tm_mday as u8,
) else {
return 0;
}
let rust_time = time::Time::try_from_hms(tm.tm_hour as u8, tm.tm_min as u8, tm.tm_sec as u8);
if rust_time.is_err() {
};
let Ok(rust_time) = time::Time::from_hms(tm.tm_hour as u8, tm.tm_min as u8, tm.tm_sec as u8) else {
return 0;
}
let rust_datetime = time::PrimitiveDateTime::new(rust_date.unwrap(), rust_time.unwrap());
let rust_odt = rust_datetime.assume_offset(time::UtcOffset::seconds(tm.tm_gmtoff));
};
let rust_datetime = time::PrimitiveDateTime::new(rust_date, rust_time);
let rust_odt =
rust_datetime.assume_offset(time::UtcOffset::from_whole_seconds(tm.tm_gmtoff).unwrap());

let result_str = rust_odt.format(format_string);
let result_str = rust_odt
.format(&time::format_description::parse(format_string).unwrap())
.unwrap();

// pad for null?
let bytes = result_str.chars().count();
Expand Down
2 changes: 1 addition & 1 deletion lib/wasi-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bitflags = "1.3.0"
cfg-if = "1.0.0"
anyhow = "1.0.66"
byteorder = "1.3"
time = "0.2"
time = { version = "0.3", features = ["formatting"] }
tracing = { version = "0.1.37" }

[dev-dependencies.pretty_assertions]
Expand Down
Loading

0 comments on commit a4fad50

Please sign in to comment.