On 9 September 2015 at 01:05, Ian Butterworth <[email protected]> wrote:
>
> I managed to make it work by removing the last 3 characters from the input
> string, and using single format characters.
> Also caught a bug that occurs when the hour in the string = 12, and it's PM.
> I believe that hour was incorrectly being shifted.. but then again, that was
> after my tweak of your example.
>
> using Base.Dates
> ds = "2015/9/8 10:05:21 AM"
> firstread = DateTime(ds[1:end-3], Dates.DateFormat("y/m/d H:M:S"))
> datetimetimeout = firstread + ((contains(ds, "PM") && hour(firstread) !=12)
> ? Hour(12) : Hour(0))
>
> Thanks for testing btw

Nice catch with the bug, I remembered wrong from my little snippet
that I had at my work box (seen below).  There was actually yet
another bug, you need to account for "12:00 AM":

    function parsedate(ds)
        clean = strip(replace(ds, r"(AM|PM)", ""))
        date  = DateTime(clean, DateFormat("u d, y H:M:S"))
        if contains(ds, "PM") && hour(date) != 12
            date += Hour(12)
        elseif contains(ds, "AM") && hour(date) == 12
            date -= Hour(12)
        end
        date
    end

Adjust the format string as needed.

    Pontus

Reply via email to