-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1622 from finos/filter-timezone
- Loading branch information
Showing
4 changed files
with
56 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright (c) 2018, the Perspective Authors. | ||
// | ||
// This file is part of the Perspective library, distributed under the terms | ||
// of the Apache License 2.0. The full license can be found in the LICENSE | ||
// file. | ||
|
||
use crate::utils::*; | ||
|
||
use chrono::{DateTime, FixedOffset, NaiveDateTime, TimeZone, Utc}; | ||
use wasm_bindgen::prelude::*; | ||
|
||
pub fn posix_to_utc_str(x: f64) -> Result<String, JsValue> { | ||
let tz = FixedOffset::west( | ||
js_sys::Date::new(&0.into()).get_timezone_offset() as i32 * 60, | ||
); | ||
|
||
if x > 0_f64 { | ||
Ok(Utc | ||
.timestamp(x as i64 / 1000, ((x as i64 % 1000) * 1000000) as u32) | ||
.with_timezone(&tz) | ||
.format("%Y-%m-%dT%H:%M:%S%.3f") | ||
.to_string()) | ||
} else { | ||
Err(format!("Unknown timestamp {}", x).into()) | ||
} | ||
} | ||
|
||
pub fn str_to_utc_posix(val: &str) -> Result<f64, JsValue> { | ||
let tz = FixedOffset::west( | ||
js_sys::Date::new(&0.into()).get_timezone_offset() as i32 * 60, | ||
); | ||
|
||
NaiveDateTime::parse_from_str(val, "%Y-%m-%dT%H:%M:%S%.3f") | ||
.map(|ref posix| { | ||
DateTime::<Utc>::from(tz.from_local_datetime(posix).unwrap()) | ||
.timestamp_millis() as f64 | ||
}) | ||
.into_jserror() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters