Skip to content

Use server time for cargo today #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/template/day.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use std::fmt::Display;
use std::str::FromStr;

#[cfg(feature = "today")]
use chrono::{Datelike, Local};
use chrono::{Datelike, FixedOffset, Utc};

#[cfg(feature = "today")]
const SERVER_UTC_OFFSET: i32 = -5;

/// A valid day number of advent (i.e. an integer in range 1 to 25).
///
Expand Down Expand Up @@ -44,7 +47,8 @@ impl Day {
impl Day {
/// Returns the current day if it's between the 1st and the 25th of december, `None` otherwise.
pub fn today() -> Option<Self> {
let today = Local::now();
let offset = FixedOffset::east_opt(SERVER_UTC_OFFSET * 3600)?;
let today = Utc::now().with_timezone(&offset);
if today.month() == 12 && today.day() <= 25 {
Self::new(u8::try_from(today.day()).ok()?)
} else {
Expand Down