Fix date_string using FixedOffset instead of Local

This commit is contained in:
RumovZ 2021-03-22 08:50:54 +01:00
parent 255daad820
commit de73232f0d
3 changed files with 13 additions and 23 deletions

View file

@ -3,7 +3,6 @@
use std::sync::Arc;
use chrono::prelude::*;
use itertools::Itertools;
use crate::err::{AnkiError, Result};
@ -60,7 +59,6 @@ struct RowContext<'a> {
deck: Option<Deck>,
original_deck: Option<Option<Deck>>,
i18n: &'a I18n,
offset: FixedOffset,
timing: SchedTimingToday,
render_context: Option<RenderContext>,
}
@ -143,7 +141,6 @@ impl<'a> RowContext<'a> {
let notetype = col
.get_notetype(note.notetype_id)?
.ok_or(AnkiError::NotFound)?;
let offset = col.local_utc_offset_for_user()?;
let timing = col.timing_today()?;
let render_context = if with_card_render {
Some(RenderContext::new(col, &card, &note, &notetype)?)
@ -159,7 +156,6 @@ impl<'a> RowContext<'a> {
deck: None,
original_deck: None,
i18n: &col.i18n,
offset,
timing,
render_context,
})
@ -202,13 +198,13 @@ impl<'a> RowContext<'a> {
"cardEase" => self.card_ease_str(),
"cardIvl" => self.card_interval_str(),
"cardLapses" => self.card.lapses.to_string(),
"cardMod" => self.card.mtime.date_string(self.offset),
"cardMod" => self.card.mtime.date_string(),
"cardReps" => self.card.reps.to_string(),
"deck" => self.deck_str()?,
"note" => self.notetype.name.to_owned(),
"noteCrt" => self.note_creation_str(),
"noteFld" => self.note_field_str(),
"noteMod" => self.note.mtime.date_string(self.offset),
"noteMod" => self.note.mtime.date_string(),
"noteTags" => self.note.tags.join(" "),
"question" => self.question_str(),
"template" => self.template_str()?,
@ -261,7 +257,7 @@ impl<'a> RowContext<'a> {
} else {
return "".into();
};
date.date_string(self.offset)
date.date_string()
};
if (self.card.queue as i8) < 0 {
format!("({})", due)
@ -295,9 +291,7 @@ impl<'a> RowContext<'a> {
}
fn note_creation_str(&self) -> String {
TimestampMillis(self.note.id.into())
.as_secs()
.date_string(self.offset)
TimestampMillis(self.note.id.into()).as_secs().date_string()
}
fn note_field_str(&self) -> String {

View file

@ -127,32 +127,28 @@ impl Collection {
}
fn card_stats_to_string(&mut self, cs: CardStats) -> Result<String> {
let offset = self.local_utc_offset_for_user()?;
let i18n = &self.i18n;
let mut stats = vec![(
i18n.tr(TR::CardStatsAdded).to_string(),
cs.added.date_string(offset),
cs.added.date_string(),
)];
if let Some(first) = cs.first_review {
stats.push((
i18n.tr(TR::CardStatsFirstReview).into(),
first.date_string(offset),
first.date_string(),
))
}
if let Some(last) = cs.latest_review {
stats.push((
i18n.tr(TR::CardStatsLatestReview).into(),
last.date_string(offset),
last.date_string(),
))
}
match cs.due {
Due::Time(secs) => {
stats.push((
i18n.tr(TR::StatisticsDueDate).into(),
secs.date_string(offset),
));
stats.push((i18n.tr(TR::StatisticsDueDate).into(), secs.date_string()));
}
Due::Position(pos) => {
stats.push((
@ -203,7 +199,7 @@ impl Collection {
.revlog
.into_iter()
.rev()
.map(|e| revlog_to_text(e, i18n, offset))
.map(|e| revlog_to_text(e, i18n))
.collect();
let revlog_titles = RevlogText {
time: i18n.tr(TR::CardStatsReviewLogDate).into(),
@ -226,8 +222,8 @@ impl Collection {
}
}
fn revlog_to_text(e: RevlogEntry, i18n: &I18n, offset: FixedOffset) -> RevlogText {
let dt = offset.timestamp(e.id.as_secs().0, 0);
fn revlog_to_text(e: RevlogEntry, i18n: &I18n) -> RevlogText {
let dt = Local.timestamp(e.id.as_secs().0, 0);
let time = dt.format("<b>%Y-%m-%d</b> @ %H:%M").to_string();
let kind = match e.review_kind {
RevlogReviewKind::Learning => i18n.tr(TR::CardStatsReviewLogTypeLearn).into(),

View file

@ -24,8 +24,8 @@ impl TimestampSecs {
}
/// YYYY-mm-dd
pub(crate) fn date_string(self, offset: FixedOffset) -> String {
offset.timestamp(self.0, 0).format("%Y-%m-%d").to_string()
pub(crate) fn date_string(self) -> String {
Local.timestamp(self.0, 0).format("%Y-%m-%d").to_string()
}
pub fn local_utc_offset(self) -> FixedOffset {