-
Notifications
You must be signed in to change notification settings - Fork 7
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
Timezone - Error in Offset #19
Comments
Note that if you used a non-UTC primitive date time with |
Thanks for the reply. let timezone = timezones::get_by_name("America/New_York").unwrap();
let d = OffsetDateTime::now_utc();
let dt= PrimitiveDateTime::new(d.date(), d.time()).assume_timezone_utc(timezone);
let offset = dt.offset(); // -4.00 CORRECT What is the cleanest way of achieving this? My case is super simple: Get a current OffSetDateTime for a provided timezone. // Similar to
OffsetDatetime::now_utc()
// May be like
OffsetDatetimeExt::now(timezone) |
If you don't need more calculations with the date time once converted to the target timezone, you can do the following: OffsetDateTime::now_utc().to_timezone(timezones::db::america::NEW_YORK) If you need more calculations in the target timezone, you can use |
Thanks for your help and your wonderful library :) // Accepted for now
let timezone = timezones::get_by_name("America/New_York").unwrap();
let d = OffsetDateTime::now_utc().to_timezone(timezone);
// Expected may be like a feature
// "America/New_York" can be a variable.
let d = OffsetDateTime::now_utc().to_timezone("America/New_York");
// How to support multi type parameter for same fn
// https://blog.rust-lang.org/2015/05/11/traits.html
`` |
I'm happy that you could find what you needed. What you're suggesting about the API is not really possible as this would require support for overload on the type of argument, moreover you don't handle the case where By the way, why don't you use the timezone types directly? |
By the way, why don't you use the timezone types directly? - Timezone is saved in DB. It's a string. // I agree that None can be produced based on input
// How about this?
OffsetDateTime::now_utc().try_timezone("America/New_York"); -> Result<OffsetDateTime, err> |
I like the idea of a |
Can you try the new |
Sure! |
time-tz= { git = "https://github.com/Yuri6037/time-tz", version = "3.0.0-rc.1.0.0", features = ["db_impl"] }
//had to include ToTimezone and db_impl is required for Tz
use time_tz::{ToTimezone, timezones, TimeZone, Offset, Tz}; Tried with this and code is working as expected. I see no changes except in use statement. |
The new use statement is expected as now the function By the way try removing the import for |
Both offsets are different. Am I doing wrong or is this a bug?
The text was updated successfully, but these errors were encountered: