зеркало из https://github.com/mozilla/glean.git
Merge pull request #679 from mozilla/convert-local-to-fixed
Use simpler conversion between local and fixed offset
This commit is contained in:
Коммит
ce97c3169d
|
@ -2,7 +2,6 @@
|
|||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
use chrono::offset::TimeZone;
|
||||
use chrono::{DateTime, FixedOffset, Local};
|
||||
|
||||
use crate::error_recording::{record_error, ErrorType};
|
||||
|
@ -49,12 +48,8 @@ pub fn get_iso_time_string(datetime: DateTime<FixedOffset>, truncate_to: TimeUni
|
|||
///
|
||||
/// This converts from the `Local` timezone into its fixed-offset equivalent.
|
||||
pub(crate) fn local_now_with_offset() -> DateTime<FixedOffset> {
|
||||
// This looks more complicated than I imagined.
|
||||
|
||||
let now: DateTime<Local> = Local::now();
|
||||
let naive = now.naive_utc();
|
||||
let fixed_tz = Local.offset_from_utc_datetime(&naive);
|
||||
fixed_tz.from_utc_datetime(&naive)
|
||||
now.with_timezone(now.offset())
|
||||
}
|
||||
|
||||
/// Truncates a string, ensuring that it doesn't end in the middle of a codepoint.
|
||||
|
@ -119,6 +114,7 @@ pub(crate) fn truncate_string_at_boundary_with_error<S: Into<String>>(
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use chrono::offset::TimeZone;
|
||||
|
||||
#[test]
|
||||
fn test_sanitize_application_id() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче