Comments (5)
@aviks, let me stress again, the confusion/problem is not in datetime2unix
/unix2datetime
, which are very straightforward methods. Let's breakdown what everything is doing here:
unix2datetime
takes the # of seconds since 1970-01-01T00:00:00 GMT and converts to aDateTime
datetime2unix
takes a JuliaDateTime
and converts it to the # of seconds since 1970-01-01T00:00:00 GMT, with an implicit assumption that theDateTime
instance is GMTnow(Dates.UTC)
returns the current wall-time as aDateTime
in GMTnow()
returns the current wall-time as aDateTime
adjusted according to the local system locale
I think your confusion comes from the fact that now()
is returning a DateTime
that will show exactly what I see in the corner screen of my system, yet that DateTime
type is inherently non-timezone aware, so passing that value to datetime2unix
falls prey to the "implicit assumption that the DateTime
is GMT".
We really can't do any better with the current, minimal Base implementation. We could change now()
to return the current wall-time in GMT and have a separate now(Dates.LOCAL)
option for current wall-time according to system time, but that's 6s to me vs. the current setup.
My point about Java being timezone aware is the fact that when you ask for the current date, they're implicitly doing now(Dates.UTC)
to get the # of unix seconds, but when you call toString
, it's automatically grabbing whatever TimeZone.getDefault()
is set to (local system settings) and displaying that GMT unix seconds to you in a nice, pretty string adjusted according to your local system's offset from GMT. It's actually storing GMT.
I guess that's another possible approach that may be less subtle for users. now()
always returns GMT, and we add the ability in Dates.format(dt, formatstring; local=true)
, so that it's explicit you want to adjust the output string to show what your current system is showing in the corner of your screen. I'd be ok with that.
Really though, I should just finish up TimeZones.jl
and if a user is ever wading into territory of needing to deal with timezones, they should automatically hook into that.
from dates.jl.
from dates.jl.
It's not the datetime2unix
and unix2datetime
functions, it's the use of Dates.now()
. Dates.now()
returns the local time as a DateTime
type that inherently doesn't associate a timezone with it. When you call jcall(jd, "toString",JString,())
, there's inherently a timezone tied to that Java date, so when you convert it to an integer, it's correctly shifting to GMT. We don't do that since there is no timezone inherently associated with our DateTime type. Hopefully that makes sense? You can call now(Dates.UTC)
to get a DateTime according to GMT instead of local time which will correspond to your java dates and time()
.
from dates.jl.
This may be a matter of perspective, but I'm not particularly convinced yet.
I think it comes down to the definition of that 10 digit number. In both Java and Unix, it is defined as number of seconds since 1-1-1970 00:00:00 GMT. Not that the epoch is defined as GMT, not local time. Defining the epoch at GMT ensures that each instance in time, at any place on earth, can be described by the same number (modulo relativistic effects, or leap seconds). If you define epoch based on local time, then that number does not define an instance in time, you need a number and a location.
Hence I think Dates.datetime2unix(dt)
should return a number based on this definition above. Which means that there is an implicit assumption about the timezone of dt
in the datetime2unix
call. And currently the assumption is that dt
is in GMT
, which is different from the assumption in now()
I think the inconsistency is best illustrated by the following invocation. I would expect that Dates.now()
and unix's now
converted via unix2datetime
should return the same result. no?
julia> Dates.now()
2015-07-11T00:25:26
julia> Dates.unix2datetime(time())
2015-07-10T23:25:27.583
Having written all that however, I am not sure if full consistency is possible without the full TZ db.
PS: FWIW, the java Date
type does not store any TZ information. Similar to julia the now()
equivalent, which is the default constructor of that type, returns the current local time.
from dates.jl.
from dates.jl.
Related Issues (20)
- Date array type wrong? HOT 1
- How to parse strings with ignorable start characters? HOT 4
- [PkgEval] Dates may have a testing issue on Julia 0.3 (2014-08-09) HOT 1
- [PkgEval] Dates may have a testing issue on Julia 0.3 (2014-08-14) HOT 1
- [PkgEval] Dates may have a testing issue on Julia 0.3 (2014-08-17) HOT 1
- [PkgEval] Dates may have a testing issue on Julia 0.3 (2014-08-20) HOT 1
- convert `DateTime` to a number of milliseconds HOT 3
- convert to epoc time HOT 4
- [PkgEval] Dates may have a testing issue on Julia 0.3 (2014-09-13)
- [PkgEval] Dates may have a testing issue on Julia 0.3 (2014-09-28) HOT 5
- Silent failure on conversion from string to DateTime HOT 2
- Allow fractions of a second? HOT 2
- wrong REQUIRE? HOT 1
- ISO 8601 Zulu dates not parsed HOT 2
- "Dates" in module "Logger" did not define a corresponding module.
- extracting microseconds HOT 1
- Info about upcoming removal of packages in the General registry
- Explain the results of ceiling Dates?
- Compatibility with Datetime HOT 2
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 dates.jl.