forked from proxmox-mirrors/proxmox
impl epoch_to_rfc3339_utc on wasm target
This commit is contained in:
parent
c01b08fea9
commit
47c9bed30d
@ -10,8 +10,8 @@ pub fn epoch_f64() -> f64 {
|
|||||||
js_sys::Date::now() / 1000.0
|
js_sys::Date::now() / 1000.0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert Unix epoch into RFC3339 local time with TZ
|
/// Convert Unix epoch into RFC3339 UTC string
|
||||||
pub fn epoch_to_rfc3339(epoch: i64) -> Result<String, Error> {
|
pub fn epoch_to_rfc3339_utc(epoch: i64) -> Result<String, Error> {
|
||||||
let js_date = js_sys::Date::new_0();
|
let js_date = js_sys::Date::new_0();
|
||||||
js_date.set_time((epoch as f64) * 1000.0);
|
js_date.set_time((epoch as f64) * 1000.0);
|
||||||
js_date
|
js_date
|
||||||
@ -20,6 +20,13 @@ pub fn epoch_to_rfc3339(epoch: i64) -> Result<String, Error> {
|
|||||||
.ok_or_else(|| format_err!("to_iso_string did not return a string"))
|
.ok_or_else(|| format_err!("to_iso_string did not return a string"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert Unix epoch into RFC3339 local time with TZ
|
||||||
|
pub fn epoch_to_rfc3339(epoch: i64) -> Result<String, Error> {
|
||||||
|
// Note: JS does not provide this, so we need to implement this ourselves.
|
||||||
|
// for now, we simply return UTC instead
|
||||||
|
epoch_to_rfc3339_utc(epoch)
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse RFC3339 into Unix epoch
|
/// Parse RFC3339 into Unix epoch
|
||||||
pub fn parse_rfc3339(input_str: &str) -> Result<i64, Error> {
|
pub fn parse_rfc3339(input_str: &str) -> Result<i64, Error> {
|
||||||
// TOTO: This should parse olny RFC3339, but currently also parse
|
// TOTO: This should parse olny RFC3339, but currently also parse
|
||||||
|
Loading…
Reference in New Issue
Block a user