Skip to content
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

WIP: Date/DateTime support through the Time module #5328

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d2a6da9
Add Datetime/Date support through the Time module
quinnj Jan 8, 2014
bb9ceee
Include Time module in Base bootup
quinnj Jan 8, 2014
b85d96e
Fix missing precision import in Time module
quinnj Jan 8, 2014
9e353c6
Add Time module exports to exports.jl
quinnj Jan 8, 2014
467dff8
Fix failing travis builds
quinnj Jan 8, 2014
14f19e3
Reduce Time exports
quinnj Jan 8, 2014
d26795a
Only export Date/Datetime
quinnj Jan 8, 2014
7cad41f
Remove old CALENDAR/TIMEZONE consts
quinnj Jan 8, 2014
3b450fc
Fix a typo
quinnj Jan 8, 2014
5778218
Change ISOCalendar/UTC to immutable types to prevent subtyping
quinnj Jan 9, 2014
f54fb8a
General code cleanup. Move typealiases together. Clean up function si…
quinnj Jan 9, 2014
ea9c2bc
Remove DatetimeRange support for now. Reworked recur() to be stand-al…
quinnj Jan 9, 2014
a0a2276
Add single argument Date string parsing.
quinnj Jan 9, 2014
0ecad4f
Remove DatetimeRange tests
quinnj Jan 9, 2014
9f12b1b
Make Period type definitions safer by providing only ::Real inner con…
quinnj Jan 11, 2014
048ef5f
Add in reworked timezone functionality
quinnj Jan 20, 2014
be61ca8
Remove leaps.jl in favor of time/leapsinfo.jl
quinnj Jan 20, 2014
d2db45a
Update Time tests
quinnj Jan 20, 2014
39ae13b
Change Offset{n} to Offset with field n
quinnj Jan 21, 2014
dc8486d
Add leapseconds.jl file
quinnj Jan 25, 2014
4591a71
Add a bunch more tests
quinnj Jan 25, 2014
98191dd
Add UTCTimezone type and make UTC an instance. Timezones are now base…
quinnj Jan 25, 2014
2936704
Restrict Period constructors to Integer. This forces the user to spec…
quinnj Jan 25, 2014
1a30cdb
Update core date alogrithms to be more robust for large negative date…
quinnj Jan 25, 2014
d75b342
Formatting issues
quinnj Jan 25, 2014
e3cbbc4
Rework firstdayofweek and lastdayofweek that now pass all tests
quinnj Jan 25, 2014
af6315c
Add keyword to recur to specify an exclusion function.
quinnj Jan 25, 2014
5238a19
Add Datetime with Periods constructor.
quinnj Jan 25, 2014
b782e1e
Few updates in the date parsing functions
quinnj Jan 25, 2014
ae7e7f6
Remove timezone functionality
quinnj Jan 25, 2014
d68a0b8
Update time.jl tests
quinnj Jan 25, 2014
ce0a172
Add missing time/leapsinfo.jl file. This is an auto-generated file th…
quinnj Jan 25, 2014
6772471
Move leapsinfo to base instead of test. Should fix travis build.
quinnj Jan 25, 2014
e6eabb4
Change Datetime => DateTime and Timezone => TimeZone
quinnj Feb 1, 2014
8716a63
Parsing improvements
quinnj Feb 1, 2014
6e9a0f1
Clean up Period conversions
quinnj Feb 1, 2014
1cc27d5
Initial whack at documentation
quinnj Feb 1, 2014
90dce0c
Update Time module tests
quinnj Feb 1, 2014
f99882d
Fix export Datetime => DateTime
quinnj Feb 1, 2014
6383218
Fix failing tests
quinnj Feb 1, 2014
6ef6e5b
Remove all time zone functionality.
quinnj Feb 8, 2014
773e963
Update time.jl tests
quinnj Feb 8, 2014
043f724
Update documentation. Add function reference and parsing examples.
quinnj Feb 9, 2014
dd271c9
Remove extra whitespace
quinnj Feb 10, 2014
b6d9745
Throw ArgumentError for out of range month arguments to Date/DateTime
quinnj Feb 10, 2014
82220b2
A few more ArgumentError throws
quinnj Feb 10, 2014
53611b8
Add convert_to_leapsecond keyword argument to unix2date to allow user…
quinnj Feb 10, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export
Operators,
Pkg,
Profile,
Time,
Sys,
Test,
BLAS,
Expand Down Expand Up @@ -952,6 +953,8 @@ export
time_ns,
toc,
toq,
Date,
Datetime,

# errors
assert,
Expand Down
59 changes: 59 additions & 0 deletions base/leaps.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Two leap-second arrays
# SETLEAPS is used when calculating the # of leap seconds from inputs
# GETLEAPS represents the leap second instant in a timeline that includes leap seconds
const SETLEAPS = [62214480000000,62230377600000,62261913600000,62293449600000,62324985600000,
62356608000000,62388144000000,62419680000000,62451216000000,62498476800000,
62530012800000,62561548800000,62624707200000,62703676800000,62766835200000,
62798371200000,62845632000000,62877168000000,62908704000000,62956137600000,
63003398400000,63050832000000,63271756800000,63366451200000,63476784000000]
const GETLEAPS = [62214480000000,62230377601000,62261913602000,62293449603000,62324985604000,
62356608005000,62388144006000,62419680007000,62451216008000,62498476809000,
62530012810000,62561548811000,62624707212000,62703676813000,62766835214000,
62798371215000,62845632016000,62877168017000,62908704018000,62956137619000,
63003398420000,63050832021000,63271756822000,63366451223000,63476784024000]

macro leapsunroll(a,r,var)
A = eval(a)
R = eval(r)
ret = Expr(:block)
push!(ret.args,:($var < $(A[1]) && return 0))
push!(ret.args,:($var >= $(A[end]) && return $(endof(A)*1000)))
push!(ret.args,searchsortedfirsttree(A[2:(endof(A)-1)],R,var))
return ret
end
# Recursively build binary search tree w/ known lookup values
# A is sorted array of lookup values
# R is return values for each index of A
# i.e. R[1] is returned for values < A[1], R[2] for < A[2], etc.
function searchsortedfirsttree(A,R,var)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this could be more generalized and live in the sort.jl file or if it's special-cased enough to just stay here. It's not really Datetime specific. It could probably also use a better name.

l = length(A)
mid = iseven(l) ? l>>>1 : (l>>>1)+1
if mid == 1
if l == 1
return :($var < $(A[1]) ? $(R[1]) : $(R[2]))
else # l == 2
return :($var < $(A[1]) ? $(R[1]) :
$var < $(A[2]) ? $(R[2]) : $(R[3]))
end
end
iftree = Expr(:if)
iftree.args = Array(Any,3)
iftree.args[1] = :($var < $(A[mid])) # condition
iftree.args[2] = searchsortedfirsttree(A[1:mid-1],R[1:mid],var)
iftree.args[3] = searchsortedfirsttree(A[mid+1:end],R[mid+1:end],var)
return iftree
end
function setleaps(ms)
@leapsunroll(SETLEAPS,[1000:1000:((endof(SETLEAPS)-1)*1000)],ms)
end
function setleapsecond(ms)
@leapsunroll([SETLEAPS[i]+1000 for i = 1:length(SETLEAPS)],
[1000:1000:((endof(SETLEAPS)-1)*1000)],ms)
end
function getleaps(ms)
@leapsunroll(GETLEAPS,[1000:1000:((endof(SETLEAPS)-1)*1000)],ms)
end
function getleapsecond(ms)
@leapsunroll([GETLEAPS[i]+1000 for i = 1:length(GETLEAPS)],
[1000:1000:((endof(SETLEAPS)-1)*1000)],ms)
end
4 changes: 4 additions & 0 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ include("graphics.jl")
include("profile.jl")
importall .Profile

# Date/Datetime
include("time.jl")
importall .Time

include("precompile.jl")

include = include_from_node1
Expand Down
Loading