From 43f55064182390d23d8166f076c790a0eb8046ce Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Wed, 2 Sep 2020 22:05:29 +0200 Subject: [PATCH] web: Implement LocaleBackend for web --- web/src/lib.rs | 9 ++++++--- web/src/locale.rs | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 web/src/locale.rs diff --git a/web/src/lib.rs b/web/src/lib.rs index 5f1ce7e96..da7b700fb 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -3,14 +3,17 @@ //! Ruffle web frontend. mod audio; mod input; +mod locale; mod navigator; mod storage; use crate::storage::LocalStorageBackend; -use crate::{audio::WebAudioBackend, input::WebInputBackend, navigator::WebNavigatorBackend}; +use crate::{ + audio::WebAudioBackend, input::WebInputBackend, locale::WebLocaleBackend, + navigator::WebNavigatorBackend, +}; use generational_arena::{Arena, Index}; use js_sys::Uint8Array; -use ruffle_core::backend::locale::NullLocaleBackend; use ruffle_core::backend::render::RenderBackend; use ruffle_core::backend::storage::MemoryStorageBackend; use ruffle_core::backend::storage::StorageBackend; @@ -158,7 +161,7 @@ impl Ruffle { let audio = Box::new(WebAudioBackend::new()?); let navigator = Box::new(WebNavigatorBackend::new()); let input = Box::new(WebInputBackend::new(&canvas)); - let locale = Box::new(NullLocaleBackend::new()); + let locale = Box::new(WebLocaleBackend::new()); let current_domain = window.location().href().unwrap(); diff --git a/web/src/locale.rs b/web/src/locale.rs new file mode 100644 index 000000000..64db279d8 --- /dev/null +++ b/web/src/locale.rs @@ -0,0 +1,20 @@ +use chrono::{DateTime, FixedOffset, Local, Offset, Utc}; +use ruffle_core::backend::locale::LocaleBackend; + +pub struct WebLocaleBackend(); + +impl WebLocaleBackend { + pub fn new() -> Self { + Self() + } +} + +impl LocaleBackend for WebLocaleBackend { + fn get_current_date_time(&self) -> DateTime { + Utc::now() + } + + fn get_timezone(&self) -> FixedOffset { + Local::now().offset().fix() + } +}