Merge pull request #679 from mozilla/convert-local-to-fixed

Use simpler conversion between local and fixed offset
This commit is contained in:
Jan-Erik Rediger 2020-02-04 10:06:49 +01:00 коммит произвёл GitHub
Родитель e8a2acd8fd 2eb5977cc4
Коммит ce97c3169d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 2 добавлений и 6 удалений

Просмотреть файл

@ -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() {