by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 03 14:45
    ammgws synchronize #464
  • Aug 03 14:34
    quodlibetor commented #464
  • Aug 03 14:33
    quodlibetor commented #464
  • Aug 03 11:56
    ammgws edited #464
  • Aug 03 11:56
    ammgws opened #464
  • Aug 01 15:54
    jnorthrup commented #450
  • Jul 31 18:40
    cecton commented #453
  • Jul 31 18:40
    cecton commented #453
  • Jul 31 18:32
    cecton commented #453
  • Jul 31 16:52
    quodlibetor closed #440
  • Jul 31 16:52
    quodlibetor commented #440
  • Jul 31 16:51
    quodlibetor commented #450
  • Jul 31 16:49
    quodlibetor commented #450
  • Jul 31 16:48
    quodlibetor commented #456
  • Jul 31 16:43
    quodlibetor closed #456
  • Jul 31 16:43
    quodlibetor commented #456
  • Jul 31 14:34
    quodlibetor commented #453
  • Jul 31 14:29
    ammgws commented #453
  • Jul 31 14:06
    quodlibetor commented #453
  • Jul 31 14:05

    quodlibetor on main

    Locales and format_localized (#… (compare)

Adam Wright
@shaladdle

oh yeah sqlite won't do much for you, mostly you'd want to store the timezone as a separate column and then use chrono-tz to back out the actual time

Yeah I might do that. This is just a hobby project for now, so not sure if that's super useful. The main thing is storing the DateTime when things happened, and if I just store a UTC time, I can always convert it to local time after reading it from the database.

Brandon W Maister
@quodlibetor
so you should use a datacenter that has leap second smearing (google cloud or aws, with their local time sources, not ubuntu and using chrony not ntpd)
yeah that is the recommended strategy, and afaik the only strategy that can be used robustly with any open source database
but (IMO) you should always only ever store UTC in databases
Adam Wright
@shaladdle
Yeah I'm doing that. In the app I work with local timezones when displaying information, but everything is stored in the db as UTC. For now all the dates are actually just automatically generated by sqlite

technically UTC has leap seconds

It seems if I did something like

  1. Make a Utc date pointing to the beginning of the year
  2. Call date.succ() until I get to the next year

Convert the result of (1) to DateTime<Local> as year_start and the result of (2) to next_year_start. I don't think there's any ambiguity there (correct me if I'm wrong), but that ends up with Utc datetimes that are (in my case) 7 hours before midnight on Jan 1 in my timezone.

And it seems hacky to call date.succ() in a loop :)
I guess if I get those utc datetimes I can just add 7 (or whatever is the offset of the local timezone) to them somehow.
Brandon W Maister
@quodlibetor
yeah you could use LocalResult::earliest or LocalResult::latest to handle that
it only returns None on a genuinely invalid time, which shouldn't happen when you're parsing something that was constructed by chrono
Adam Wright
@shaladdle
Ahh interesting.
Brandon W Maister
@quodlibetor
but timezones do occasionally change entirely, because governments are indecisive
Adam Wright
@shaladdle
I thought that because of DST in some timezones you might be able to specify a NaiveDateTime that didn't exist.
Because time skipped that hour
Brandon W Maister
@quodlibetor
yeah you can write times that don't exist at all
if you try and parse a utc time as local time then that could be invalid
Adam Wright
@shaladdle
Oh really?
Brandon W Maister
@quodlibetor
but you can store utc, parse utc, convert to local, which is the correct way to handle it
like utc never skips an hour
so there are hours that exist in utc that don't exist in some timezones
Adam Wright
@shaladdle
What's an example? Daylight savings is the scenario that comes to mind for me, and I think every hour that exists in UTC should be expressible in a daylight savings timezone.
But maybe there are other ones
Like if time skips from 1AM to 2AM in the pacific timezone, then both of those still have some corresponding UTC time
Same if we go back to 2AM at 3AM
(for the other direction)
Brandon W Maister
@quodlibetor
right, you would need to write something down as utc, and then parse it as local in order for it to be invalid
if you convert to utc before storing then it is always valid
you need to make a mistake in serialization or deserialization in order to have this problem
Adam Wright
@shaladdle
hm ok
Brandon W Maister
@quodlibetor
like the time 01:30 exists in utc on that date, but if you try to parse that as local (instead of parsing it as utc and converting to local) then you're going to get an invalid time
Adam Wright
@shaladdle
When you say "if you try to parse that as local", what chrono calls would that be? I think I might be misinterpreting the parsing direction in your statement.
Brandon W Maister
@quodlibetor
but the serialization order Local -> Utc -> Db and Db -> Utc -> Latest -> Local should always be valid
Adam Wright
@shaladdle
Right, that's the approach I'm taking. I just feel like maybe I'm mis-using the API when I come up with this time range, so I'm running into ambiguity. But I guess you're saying I can use earliest and latest and unwrap safely in my code above?
(and thanks for all the helpful advice, I appreciate you taking the time!)
Brandon W Maister
@quodlibetor
I believe that that should always be safe, yeah
If this is running in production I'd still recommend using if let to guard against mistakes crashing your server, but for a hobby thing I think it'd be fine
Adam Wright
@shaladdle
Yeah I agree. It's just a CLI tool for personal use so I probably won't worry too much about it.
Brandon W Maister
@quodlibetor
yeah I believe that that should be fine in 100% of cases
like unless the government literally deletes a day after the fact or something
or more realistically if your tzdata file changes after the time was stored because it had bugs
the international tzdb recently had a bug in brazil I think? so it does happen
Adam Wright
@shaladdle
Yeah, makes sense. Bugs are hard to avoid.
Buy Bitcoin [uDevNull]
@udevnull_twitter
Hey guys, any idea how I can get a timezone as an int of some sorts?
Brandon W Maister
@quodlibetor
what kind of int would you like it to be?
FixedOffset::local_minus_utc will give you "minutes away from utc" @udevnull_twitter https://docs.rs/chrono/0.4.11/chrono/offset/struct.FixedOffset.html#method.local_minus_utc
heca-project
@heca-project
Would it be possible to add Duration to NaiveDateTime without checking for overflow? I do a lot of adding and I check for overflows outside the main loop, so it wouldn't overflow anyways.
Brandon W Maister
@quodlibetor
@heca-project yeah we could add some _unchecked methods, I'd be happy to take a PR.
Jonathan Dickinson
@jcdickinson
Hey! I have fixed a test in my project that fails on my machine/time-zone (related to DST), [edit] and want to make sure that it is tested correctly on the CI server. Is there a way to fake the timezone in Chrono for testing purposes?
Benno Rice
@jeamland
Hi, I'm looking at #380 / #384 and seeing if I can implement a version of Period that is generic over Datelike + Timelike however the biggest issue there is that it really wants to work off a "DateTimelike" that can do things like work out what a "DateTimelike" + a Duration is.
An idea how I'd go about tweaking things so I had that?