Design issue. The Time.getCurrentTime function returns the elapsed (default) seconds since midnight local time, not Unix epoch. Why? This behavior doesn't seem that useful.
getCurrentDate which returns a (year, month, day) tuple; why not this function too? Maybe something like (hour, minute, second, timezone) :(int, int, real, TimeZone).(Documenting this issue before I forget. It's not a priority for me at all.)
@bradcray @ben-albrecht I did some workaround and came across the following functions, please have a look and give your inputs.
1) Python - datetime.now().time() returns a time object with (hours, minutes, seconds)
datetime.time(21, 34, 51, 343376)
2)Javascript - We have a single function that gives us both time and date.
var today = new Date();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
3) In c++ we have a single time() function which returns Day Month Date hh:mm:ss Year
Mostly I saw two types of behaviour in get current time type functions-
1) A function returning time in (Hours, Minutes, Seconds) format.
2) Or a single function, returning both current time and the present date.
Thanks!
@Aniket21mathur - A few comments/questions:
Time module rather than the DateTime module, so comparisons to other languages should reflect that.There are some of the time modules that return the current date, along with the time. For example in Go:-
now := time.Now()
p(now)
returns something like
2012-10-31 15:50:13.793654 +0000 UTC
- Are all time functions returning time since Unix epoch?
Not all, some like time.time() in Python returns time since Unix epoch.
- Do any time functions include the time zone like @BryantLam proposes above?
Yes, the time.Now() in Go as described above, also time.timezone in python returns the offset in seconds of the local time zone from UTC.
Swift3 seems to have a single Date() function that is used to get the components(hours, minutes, seconds) of current time.
In our case since Chapel has a function to get the current date, In my opinion Time.getCurrentTime can return (hour, minute, second, TimeZone) as suggested by @BryantLam.
Also, I observe that the getCurrentTime function is used in the Random module and in a lot of test modules. So changing the return of this module will also require changes in other modules.
Thanks!
@Aniket21mathur - thanks for driving this issue forward. As a heads up, the core dev team is working towards finalizing the Chapel 1.21 release, and probably won't have much time to discuss this design issue until things calm down.
You are welcome to comment with other information you think is helpful / relevant in coming to a decision, and even propose a design for our Time.getCurrentTime in the meantime.
You are welcome to comment with other information you think is helpful / relevant in coming to a decision, and even propose a design for our
Time.getCurrentTimein the meantime.
Sure. :smile:
For those following this issue, we're currently planning on deprecating Time.getCurrentTime() and friends in favor of capabilities in the DateTime module. Time is a module that dates from the early years of the project when we needed some capabilities to get up and running. DateTime reflects a more recent effort to support a more complete and better designed set of functionality for reasoning about dates and times.
Most helpful comment
For those following this issue, we're currently planning on deprecating
Time.getCurrentTime()and friends in favor of capabilities in theDateTimemodule.Timeis a module that dates from the early years of the project when we needed some capabilities to get up and running.DateTimereflects a more recent effort to support a more complete and better designed set of functionality for reasoning about dates and times.