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 more information about a timezone like start of DST and offset of DST? #130

Open
doivosevic opened this issue May 6, 2023 · 5 comments

Comments

@doivosevic
Copy link

I'm trying to convert some old c++ code to rust but I'm lacking some information about the timezones. For instance:

  • when does DST start and end for a certain timezone?
  • how big is the offset for DST?

I know I can get offset from UTC if I have some datetime but I would prefer if I wouldn't have to iterate through all days of year and then hours of that day to find when does a certain DST start or end. I see c++ boost has these methods, is there a way to extract this information? From what I can see in boos code they are extracting this data from some string but I didn't find what they are parsing.

I need stuff like dst_offset https://github.com/dials/boost/blob/master/boost/date_time/local_time/posix_time_zone.hpp#L177 and dst_local_start_time https://github.com/dials/boost/blob/master/boost/date_time/local_time/posix_time_zone.hpp#L152

@djc
Copy link
Contributor

djc commented May 26, 2023

In general, there's no fixed start date/time per timezone -- those things can change from year to year. What is the problem you are trying to solve?

@doivosevic
Copy link
Author

I'm trying to convert old c++ code directly to rust as closely as possible to avoid regression and then later to convert to idiomatic rust. In any case, I'd like to be able to avoid having to rewrite this datetime management part of code so that it doesn't need information such as "dst offset" and "local dst start time". I understand it's year based but as I understand this boost code can read this from tzfile, is that correct?

@djc
Copy link
Contributor

djc commented May 26, 2023

Maybe you should go to one level lower and look directly for crates that parse tzinfo files?

@doivosevic
Copy link
Author

ok but is providing boost equivalent tz api something chrono might want to do?

@djc
Copy link
Contributor

djc commented Jun 1, 2023

I don't think we will implement APIs that provide a DST offset or local DST start time without some kind of date/time input. I would be willing to review a PR that adds some kind of API where DateTime<chrono_tz::Tz> provides next_offset_change() and prev_offset_change() methods.

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

2 participants