Skip to content

Commit a9ba301

Browse files
authored
fix: use server time for cargo today (#61)
1 parent 335f263 commit a9ba301

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/template/day.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use std::fmt::Display;
33
use std::str::FromStr;
44

55
#[cfg(feature = "today")]
6-
use chrono::{Datelike, Local};
6+
use chrono::{Datelike, FixedOffset, Utc};
7+
8+
#[cfg(feature = "today")]
9+
const SERVER_UTC_OFFSET: i32 = -5;
710

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

0 commit comments

Comments
 (0)