Skip to content

Commit

Permalink
Fix Chrono Deprecation Errors. (#35)
Browse files Browse the repository at this point in the history
* Fix Chrono Deprecation.

* Fix rust-embed errors.

* Remove unused code.
  • Loading branch information
futursolo committed Sep 9, 2023
1 parent 254990e commit 849bceb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 24 deletions.
26 changes: 16 additions & 10 deletions crates/fl-www-cli/src/feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Feed {
let mut zh_writings = Vec::new();
let mut en_writings = Vec::new();

let mut latest = NaiveDate::from_ymd(1970, 1, 1);
let mut latest = NaiveDate::from_ymd_opt(1970, 1, 1).expect("failed to create date");

for writing in metadata.writings() {
if writing.date > latest {
Expand All @@ -34,18 +34,22 @@ impl Feed {
};
}

let time = NaiveTime::from_hms(0, 0, 0);
let time = NaiveTime::from_hms_opt(0, 0, 0).expect("failed to create date");
let latest_datetime = NaiveDateTime::new(latest, time);
let latest_datetime: DateTime<FixedOffset> =
DateTime::from_utc(latest_datetime, FixedOffset::east(0));
let latest_datetime: DateTime<FixedOffset> = DateTime::from_naive_utc_and_offset(
latest_datetime,
FixedOffset::east_opt(0).expect("failed to create date"),
);

let zh_entries = zh_writings
.iter()
.map(|m| {
let time = NaiveTime::from_hms(0, 0, 0);
let time = NaiveTime::from_hms_opt(0, 0, 0).expect("failed to create date");
let datetime = NaiveDateTime::new(m.date.to_owned(), time);
let datetime: DateTime<FixedOffset> =
DateTime::from_utc(datetime, FixedOffset::east(0));
let datetime: DateTime<FixedOffset> = DateTime::from_naive_utc_and_offset(
datetime,
FixedOffset::east_opt(0).expect("failed to create date"),
);

EntryBuilder::default()
.title(Text::plain(&m.title))
Expand All @@ -67,10 +71,12 @@ impl Feed {
let en_entries = en_writings
.iter()
.map(|m| {
let time = NaiveTime::from_hms(0, 0, 0);
let time = NaiveTime::from_hms_opt(0, 0, 0).expect("failed to create date");
let datetime = NaiveDateTime::new(m.date.to_owned(), time);
let datetime: DateTime<FixedOffset> =
DateTime::from_utc(datetime, FixedOffset::east(0));
let datetime: DateTime<FixedOffset> = DateTime::from_naive_utc_and_offset(
datetime,
FixedOffset::east_opt(0).expect("failed to create date"),
);

EntryBuilder::default()
.title(Text::plain(&m.title))
Expand Down
7 changes: 0 additions & 7 deletions crates/fl-www-core/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ pub struct Reply {
pub created_at: DateTime<Utc>,
}

impl Reply {
/// Returns the key in the storage.
pub fn key(&self) -> String {
format!("{}:{}:{}", self.lang, self.slug, self.id)
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ReplyInput {
pub content: String,
Expand Down
2 changes: 1 addition & 1 deletion crates/fl-www-core/src/object_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ impl FromStr for ObjectId {

impl fmt::Display for ObjectId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", hex::encode(&self.0))
write!(f, "{}", hex::encode(self.0))
}
}
6 changes: 4 additions & 2 deletions crates/fl-www/src/contexts/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ fn get_theme_kind() -> ThemeKind {
let persisted_state: Option<PersistedThemeState> = LocalStorage::get(STORAGE_KEY).ok();

if let Some(m) = persisted_state {
let updated =
DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(m.last_updated, 0), Utc);
let updated = DateTime::<Utc>::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(m.last_updated, 0).expect("failed to create date"),
Utc,
);

// theme selection is persisted for 6 hours.
if Utc::now() - updated <= Duration::hours(6) {
Expand Down
16 changes: 12 additions & 4 deletions crates/fl-www/src/i18n.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
use i18n_embed::fluent::{fluent_language_loader, FluentLanguageLoader};
use i18n_embed::{LanguageLoader, WebLanguageRequester};
use once_cell::sync::Lazy;
use rust_embed::RustEmbed;
use unic_langid::LanguageIdentifier;
use yew_router::prelude::Routable;

use crate::prelude::*;

#[derive(Debug, RustEmbed)]
#[folder = "../../i18n"] // path to the compiled localization resources
struct Localizations;
mod l10n_embed {
// We only want to suppress this limit for Localization.
#![allow(non_upper_case_globals)]

use rust_embed::RustEmbed;

#[derive(Debug, RustEmbed)]
#[folder = "../../i18n"] // path to the compiled localization resources
pub(super) struct Localizations;
}

use l10n_embed::Localizations;

pub(crate) trait LanguageExt {
fn detect() -> Self;
Expand Down

0 comments on commit 849bceb

Please sign in to comment.