Comments (11)
I believe the ISO date format (with timezone) is an absolute timestamp, not a relative one—i.e. the offset is always the offset from GMT, not relative to your current timezone.
If that's true, then I believe the two ways of specifying the timezone should be mutually exclusive, and I believe the ISO offset should take precedence.
If both are given, I see no issue with ignoring the second argument (you could also log a warning).
This would also be very easy to understand for users of this library (as opposed to the complex maths of relative offsets), and it makes it compatible with anyone who is working with dates from a standard API (like I am) which include timezone in the timestamp.
I don't know the library well enough to suggest how this should be suggested, but if you agree I might be able to take a look at putting a PR in... 👍
from spacetime.
@spencermountain yeah that works! as long as the warning can be disabled in config... 😉
from spacetime.
Can see this has been released—thanks! Should this be closed?
from spacetime.
hey Sam, yeah i think I see what you mean.
if i can remember, i started parsing the timestamp, ran into the timezone, and thought, hmm should this over-ride a timezone entered as the second param? Then i thought, how should we guess which timezone it is, given the offset? then i thought, man, it's almost lunch time.
so yeah, my bad ;)
if you pass a iana timezone in the second param, you should get your expected behaviour I believe.
would be happy to merge any solution to handling this. up to you!
cheers
from spacetime.
hey, maybe this?:
we add UTC-7
, and so forth, to the zonefile, which have no dst changes.
if we get a -0700
suffix on the timestamp, we overwrite (any?) given timezone as second param, ... unless it's ...currently the same offset?
worse is the condition when you say spacetime('xxx--0700', 'Europe/London')
- because then it's a double-conversion. I suppose we could try to support that - ie find x-oclock in 7-offset, then find out what time that is in london.
yikes!
(just thinking aloud)
from spacetime.
Couple points of clarification: ISO 8601 defines a broad standard for representation of dates, not a singular form for dates.
Additionally, I believe offsets are relative to UTC, not GMT. In the real world they are basically the same, but represent different things. One example: iirc the actual GMT timezone isn't used while the UK goes on British Summer Time.
from spacetime.
Of course, my bad about GMT ≠ UTC, I get lazy being in the UK...
Regardless of the broad standard, I still believe the absolute offset is the easiest way to work with timezones if you'd like to accept the format which includes a timezone offset in the timestamp? Although open to any ideas you'd prefer 😊
from spacetime.
hey, got this working and I'm somewhat happy with it - atleast it didn't destroy any passing-tests.
this look alright?
will be in v3.0
from spacetime.
@spencermountain LGTM! Out of curiosity, are you going with ignoring the second argument if the first has a timezone included? Or has the API changed in 3.0?
Thanks for this, going to be really helpful!
from spacetime.
hey yeah, it would ignore the 2nd argument if it's there.
I thought about adding a warning message if that's the case. Maybe I should do that today.
from spacetime.
yeah, new console.warn behaviour in the next release:
const s = spacetime('2017-04-03T08:00:00-0700', 'Canada/Eastern')
/* - Setting timezone to: 'Etc/GMT-7'
from ISO string '-0700'
overwriting given timezone: 'Canada/Eastern'*/
what do you think Sam?
from spacetime.
Related Issues (20)
- Unexpected results near DST 2023 boundaries (Europe/Helsinki) HOT 4
- Month number is always -1 HOT 3
- ISO offset vs IANA code ambiguities HOT 5
- DST Result for "Asia/Tehran" is wrong HOT 1
- [Typescript] Could not find declaration file for module 'spacetime' HOT 1
- dayOfYear in leap years HOT 3
- Failing timezone conversion from Zulu to Europe/Rome HOT 1
- Times of the day seem illogical HOT 9
- week function not working correctly HOT 8
- Specific date is not getting the correct epoch HOT 1
- toNativeDate does not factor in timezone offset HOT 3
- Question about making plugins HOT 4
- The new zone `America/Ciudad_Juarez` is missing HOT 3
- Spacetime not working in MacOS Sonoma (Cannot find timezone named: 'cet'. Please enter an IANA timezone id) HOT 7
- Epoch values not updating for different timezones HOT 4
- Incorrect Africa/Casablanca offset HOT 3
- Daylight savings error with timezone HOT 1
- Africa/Cairo: wrong TZ offset HOT 3
- Subtract TZ offset
- Module '"spacetime"' has no exported member 'Spacetime'. Did you mean to use 'import Spacetime from "spacetime"' instead? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spacetime.