Skip to content
This repository has been archived by the owner on Dec 5, 2020. It is now read-only.

Refactor #2

Merged
merged 34 commits into from
Oct 16, 2015
Merged

Refactor #2

merged 34 commits into from
Oct 16, 2015

Conversation

Michael-Klassen
Copy link
Contributor

Refactor DateTimeParser

omus and others added 2 commits October 9, 2015 10:11
- Generating Dict similar to those used in Base.Dates
  eg. DAYOFWEEKTOVALUE
@codecov-io
Copy link

Current coverage is 100.00%

Merging #2 into master will not affect coverage as of ac867e8

@@            master      #2   diff @@
======================================
  Files            1       1       
  Stmts          314     317     +3
  Branches         0       0       
  Methods          0       0       
======================================
+ Hit            314     317     +3
  Partial          0       0       
  Missed           0       0       

Review entire Coverage Diff as of ac867e8

Powered by Codecov. Updated on successful CI builds.

@Michael-Klassen
Copy link
Contributor Author

Would like to "Perform lowercase earlier in _parsedate. Probably just do map(lowercase, X).
Then you can remove the random lowercase calls peppered throughout that function" but timezone_infos is case sensitive.

@Michael-Klassen
Copy link
Contributor Author

"Eventually res could become res = Union{Period,TimeZone}[]. When you are ready to make a Date you can ZoneDateTime(res...). That will call ZonedDateTime(parts::Union{Period,TimeZone}...). Both Date and DateTime also have these constructors"

@Michael-Klassen
Copy link
Contributor Author

"I'd also like _parsedate to be broken into smaller functions. For example extract just the timezone from the tokens"

return i
end

function processymd!(res::Dict, ymd::Array, mstridx=-1; yearfirst=false, dayfirst=false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just have processymd return a tuple of Year, Month, Day? ymd should be ymd::Array{Int}. mstridx is a bad variable name and should be changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll change it to return a tuple instead of passing res by reference. Any preferences on what I should rename mstridx to?

Copy link
Contributor

Choose a reason for hiding this comment

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

month_index?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason why processymd does not just return a Year, Month and Day is because there isn't always a Year, Month and Day to return.

i += 2
if i+1 <= len && tokens[i] == "." && isdigit(tokens[i+1])
res["millisecond"] = round(Int, 1000 * parse(Float64, string(".", tokens[i+1])))
temp = 1000 * parse(Float64, string(".", tokens[i+1]))
res["millisecond"] = Millisecond(round(Int, temp))
i += 2
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this section is a little too fragile?

julia> parse(DateTime, "5:4.5")
2015-01-01T05:04:30

julia> parse(DateTime, "5:4:3.5")
2015-01-01T05:04:03.5

julia> parse(DateTime, "5:4.5:3.5")
ERROR: Failed to parse date
 in _parsedate at /Users/omus/.julia/v0.4/DateTimeParser/src/DateTimeParser.jl:361
 in parse at /Users/omus/.julia/v0.4/DateTimeParser/src/DateTimeParser.jl:92

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ending with a decimal is a special case. I'm not sure we want to support having a floats in the middle.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fair

@omus
Copy link
Contributor

omus commented Oct 13, 2015

Good work overall!

@omus
Copy link
Contributor

omus commented Oct 15, 2015

  • Rename package to "DateParser.jl"? There won't be a perfect name as this covers Date, DateTime, and ZonedDateTime types but I think DateParser is the best
  • Add appveyor badge to README
  • JUMP, PERTAIN, UTCZONE should be Arrays rather than Tuples so they can be extended

res.month = get(res.month, Month(default))
res.day = get(res.day, Day(default))

return Date(get(res.year), get(res.month), get(res.day))
Copy link
Contributor

Choose a reason for hiding this comment

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

Could shorten the code to:

return Date(
    get(res.year, year(default)),
    get(res.month, month(default)),
    get(res.day, day(default)),
)

@@ -152,25 +167,26 @@ function _parsedate(datetimestring::AbstractString; fuzzy::Bool=false,
# Token is a number
i += 1 # We want to look at what comes after the number
if length(ymd) == 3 && tokenlength in (2,4) &&
(i>=len || (tokens[i] != ":" && !haskey(HMS, lowercase(tokens[i]))))
(i>=len || (tokens[i] != ":" && !haskey(HMS[locale], lowercase(tokens[i]))))
Copy link
Contributor

Choose a reason for hiding this comment

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

Condition can be changed to length(ymd) == 3 && tokenlength in (2,4) && i > len without causing the testcases to fail. Add additional tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll add a test for it parse(DateTime, "19991212 0259+1:00")

@Michael-Klassen
Copy link
Contributor Author

The 32 bit win build is broken because the released TimeZones 32 bit build is broken

@omus
Copy link
Contributor

omus commented Oct 16, 2015

Which is broken because LightXML 32-but is broken because WinRPM 32-bit is broken. All good

Michael-Klassen added a commit that referenced this pull request Oct 16, 2015
@Michael-Klassen Michael-Klassen merged commit 9537810 into master Oct 16, 2015
@Michael-Klassen Michael-Klassen deleted the refactor branch December 1, 2015 15:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants