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
convert(to timeZone:) "feels wrong" for Absolute<Day> #34
Comments
convert(to timeZone:)
"feels wrong" for Absolute<Day>
It seems to me that a "time zone" matters more when a more granular hour or minute is involved, as opposed to only the calendrical day. March 16th is March 16th for half the world at a time; unless you're talking about a particular part of March 16th, which is different depending upon the time zone, one doesn't often consider the other time zones. I do think this issue needs to be decided. It feels odd to, sans documentation, pick a time as arbitrary as noon o'clock and convert that to the other time zone. I like your idea of breaking the function apart for What comes to my mind is somehow disallowing I wonder too about |
These are great points. I'll think about the proper way to solve this. I'm thinking it might involve falling back to a dateComponents → date approach. |
I was thinking about this a bit more. The current behavior is technically correct, and the confusion is arising from a bad API name (and please LMK if you disagree). The conversion methods, as they currently stand, are about converting temporal coordinates from one localized representation to another. The most reliable way of doing that is to convert based off the approximate midpoint of the temporal range, and use that as the base value for conversion. In other words, the temporal range of There is a different kind of conversion, which is "I have this set of calendar components, and I want to get a calendar value that has these same components but in another timezone". In other words, "I have For most calendar units, these two kinds of conversions are largely equivalent. But when we get down to the smaller units, we get tripped up on the distinction between these two.
What suggestions do you have on naming these kinds of conversions, and how would you like to see them differentiated from each other? |
My current thinking on the names are |
That sounds good to me. As long as the documentation is explicit about the differences and quirks between them (I'm okay reading well-written documentation paragraphs) I'm okay with those signatures. |
Although, "time range" feels a bit clunky, since that phrase isn't common parlance in the package. |
Are there use cases for Alternatively, I wonder if the same-components-with-different-time-zone should actually be considered a "conversion"...what do you think of |
I believe I've addressed this in the latest code, here: https://github.com/davedelong/time/blob/main/Sources/Time/4-Fixed%20Values/Fixed%2BConversion.swift#L40 There are targeted methods for converting This will be included in the upcoming 1.0 release. |
This shipped in 1.0. There are a couple alternatives:
|
convert(to timeZone:)
behaves consistently for allT
inAbsolute<T>
and in all other cases besides<Day>
it behaves intuitively. For example, taking March 16 2020 at 12:00 PM EST (Absolute<Minute>
) and converting it to PST gives you a different set of date components, which "feels" right.Converting March 16, 2020 (
Absolute<Day>
) from UTC to NZDT (UTC+13) gives March 17, 2020 because internally it takes the approximate midpoint of March 16, 2020 UTC (noon on that day in UTC) and uses the date components of that instant in NZDT, which is 1:00AM March 17 NZDT. This "feels" wrong (to me).The behaviour for anything smaller than
Day
is intuitively correct (as in the first example above), and for anything bigger thanDay
is intuitively correct because the midpoint of a month, year, or era will end up in the same month, year, or era (AFAIK, maybe this is one of those falsehoods programmers believe) because time zones are never several days apart from each other.I suppose we can't change just the behaviour of
convert(to timeZone:)
forAbsolute<Day>
but I wonder if we could provide asameDay(in timeZone:)
or something?This realization made me rethink the way I was doing things and in my own app this isn't actually something I need, so maybe things are fine as-is, or maybe
convert(to timeZone:)
just needs some docs explaining this?The text was updated successfully, but these errors were encountered: