diff --git a/experment/sweeps_to_note.md b/experment/sweeps_to_note.md new file mode 100644 index 00000000..495d5e66 --- /dev/null +++ b/experment/sweeps_to_note.md @@ -0,0 +1 @@ +coveralls is to slow right now diff --git a/src/dateformat.jl b/src/dateformat.jl index fb09ebf3..13a2e9fa 100644 --- a/src/dateformat.jl +++ b/src/dateformat.jl @@ -3,8 +3,33 @@ Dates.default_format(::Type{NanoDate}) = ISONanoDateFormat NanoDate(nd::NanoDate, df::DateFormat) = format(nd, df) -# returns the specifier part as a string -Base.String(df::DateFormat) = string(df)[12:end-1] +# get the specifier part of a DateFormat as a string +# restricts the specifier to 9 subsecond digits +function safestring(df::DateFormat) + str1 = string(df)[12:end-1] + str2 = "" + sepidx = findlast('.', str1) + isnothing(sepidx) && return str1 + + if endswith(str1, "Z") + str1 = str1[1:end-1] + str2 = "Z" + elseif endswith(str1, "m") # "±hh:mm" or "±hhmm" + pmidx = findlast('h', str1) + if isnothing(pmidx) || pmidx == 1 || (str1[pmidx-1] != '+' || str1[pmidx-1] != '-') + return str1 + else + pmidx -= 1 + str1 = str1[1:pmidx-1] + str2 = str1[pmidx:end] + end + end + + sidxlast = findlast('s', str1) + sidxmax = sepidx + 9 + sidxlast = min(sidxlast, sidxmax) + str1[begin:sidxlast] * str2 +end omit(needle::Nothing, haystack::Nothing) = nothing omit(needle, haystack::Nothing) = nothing @@ -51,7 +76,7 @@ function findeach(needle, haystack) end function nanodateformat(nd::NanoDate, df::DateFormat; subsecsep::Union{Char,AbstractString}='.') - dfstr = String(df) + dfstr = safestring(df) scount, sindices = findeach('s', dfstr) idxsubsecsep = subsecsep == "" ? nothing : findlast(subsecsep, dfstr) if !isnothing(idxsubsecsep) diff --git a/src/strings.jl b/src/strings.jl index b8e1c061..69794e19 100644 --- a/src/strings.jl +++ b/src/strings.jl @@ -82,7 +82,7 @@ charvec2string(chrs::AbstractVector{Char}) = foldl(*, chrs; init = "") function nanodate_format(nd, df) nooffset(df) indices = indexperiods(df) - dfstr = String(df) + dfstr = safestring(df) chrs = string2charvec(dfstr) indices = NamedTuple{(:yr, :mn, :dy, :hr, :mi, :sc, :ss)}(indices) # omit offset field syms = keys(indices) @@ -142,7 +142,7 @@ end subsec_str = lpad(subsec_value, 9, '0') supersec = datetime - Millisecond(datetime) - dfstr = String(df) + dfstr = safestring(df) str = Dates.format(datetime, df) value(nd.nanosecs) == 0 && return str @@ -195,7 +195,7 @@ function nanodate_format(nd, df, sep) str end -nooffset(df::DateFormat) = nooffset(String(df)) +nooffset(df::DateFormat) = nooffset(safestring(df)) function nooffset(str::AbstractString) if occursin('+', str) throw(ArgumentError("utc offsets are not supported in format(), use timestamp()")) @@ -203,7 +203,7 @@ function nooffset(str::AbstractString) end -separate_offset(df::DateFormat) = separate_offset(String(df)) +separate_offset(df::DateFormat) = separate_offset(safestring(df)) function separate_offset(str::AbstractString) if isempty(str) || isdigit(str[end]) @@ -323,7 +323,7 @@ function getpart(r::UnitRange, str) end getpart(x::Nothing, str) = "0" -indexperiods(df::DateFormat) = indexperiods(String(df)) +indexperiods(df::DateFormat) = indexperiods(safestring(df)) function indexperiods(dfstr::String) str = strip(dfstr)