Skip to content

Commit

Permalink
Add nowutc() function that is similar to now(), but returns the curre…
Browse files Browse the repository at this point in the history
…nt system time in UTC. Also added tests and docs, as well as doc updates for the new day of week formatting.
  • Loading branch information
quinnj committed Aug 25, 2014
1 parent 9f13004 commit 880d6f6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions base/dates/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function now()
return DateTime(tm.year+1900,tm.month+1,tm.mday,tm.hour,tm.min,tm.sec)
end
today() = Date(now())
nowutc() = unix2datetime(time())

rata2datetime(days) = DateTime(yearmonthday(days)...)
datetime2rata(dt::DateTime) = days(dt)
Expand Down
9 changes: 8 additions & 1 deletion doc/stdlib/dates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ alternatively, you could call ``using Dates`` to bring all exported functions in
``M`` 00 Matches minutes
``S`` 00 Matches seconds
``s`` .500 Matches milliseconds
``e`` Mon, Tues Matches abbreviated days of the week
``E`` Monday Matches full name days of the week
``yyyymmdd`` 19960101 Matches fixed-width year, month, and day
=============== ========= ===============================================================

Expand Down Expand Up @@ -87,7 +89,12 @@ alternatively, you could call ``using Dates`` to bring all exported functions in
.. function:: now() -> DateTime

Returns a DateTime corresponding to the user's system
time.
time including the system timezone locale.

.. function:: nowutc() -> DateTime

Returns a DateTime corresponding to the user's system
time as UTC/GMT.

Accessor Functions
~~~~~~~~~~~~~~~~~~
Expand Down
3 changes: 2 additions & 1 deletion test/dates/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@
@test Dates.datetime2julian(Dates.DateTime(2013,12,3,21)) == 2456630.375

@test typeof(Dates.now()) <: Dates.DateTime
@test typeof(Dates.today()) <: Dates.Date
@test typeof(Dates.today()) <: Dates.Date
@test typeof(Dates.nowtuc()) <: Dates.DateTime

0 comments on commit 880d6f6

Please sign in to comment.