I am displaying a date on the screen using the chrono crate.
The intention is to show the date in the users preferred time or UTC if no is set.
I have the UTC default set up, but I am unsure on the best method to record the user's timezone and how to apply that to the current date.
Note: date
might not be set here so I'd prefer to modify date
rather than use a different constructor.
let mut date: DateTime<UTC> = UTC::now();
//Convert to the User's Timezone if present
if let Some(user) = user {
//Extract the timezone
date.with_timezone(TimeZone::from_offset(&user.timezone));
}
let date_text = date.format("%H:%M %d/%m/%y").to_string();
What I would like is a type to use for user.timezone
and an example on how to set the date.