Skip to content
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

How to get "now" with DateTime<Timezone>? #624

Closed
tobymurray opened this issue Nov 17, 2021 · 3 comments
Closed

How to get "now" with DateTime<Timezone>? #624

tobymurray opened this issue Nov 17, 2021 · 3 comments

Comments

@tobymurray
Copy link

Analogous to Utc::now, I'd like to get now as a DateTime<Timezone> for a given timezone, would this be the idiomatic way to do so?

Utc::now().with_timezone(timezone)

Similar to #169, I struggled a lot more than I think I ought to have to try and do some relatively straightforward seeming tasks.

I'd love to:

  • hear if there's a better way to do it
  • add to the documentation (open to suggestions where would make a good fit, maybe right on DateTime#now?)
  • commiserate with how hard it is to make an intuitive time library when it's so damn complicated! Thanks for all the work.
@epipheus
Copy link

I'd like to mention that many of us use DateTimeWithTimezone as DB storage by default but optionally still log UTC based date times which is just +0. The current Utc::now().with_timezone(&FixedOffset::east(0)) feels non-obvious and verbose and isn't terribly well documented. as mentioned in #169. Utc::now.as_fixed_offset() or Utc::now.as_date_with_timezone(). Even is as verbose, feels readable and obvious. My 2 cents.

@djc
Copy link
Contributor

djc commented Sep 28, 2022

@epipheus PR welcome!

@pitdicker
Copy link
Collaborator

Analogous to Utc::now, I'd like to get now as a DateTime<Timezone> for a given timezone, would this be the idiomatic way to do so?

Utc::now().with_timezone(timezone)

Yes, this is the idiomatic way to do it.

#1030 added DateTime::fixed_offset and #1192 will add some examples to the documentation on using Utc::now() and Local::now().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants