On 8 September 2015 at 22:31, Ian Butterworth <i.r.butterwo...@gmail.com> wrote:
>
> On Tuesday, 8 September 2015 17:27:25 UTC-4, Ian Butterworth wrote:
>>
>> I current use Calendar.jl to convert a datetime that contains AM/PM to the
>> datetime type like this:
>> datetime_string = "2015-08-12 12:01:23 PM"
>> timeout = unix2datetime(Calendar.parse(datetime_string,
>> timein).millis/1000)
>>
>> I'd like to do it without calendar.jl if possible.
>>
>> Any ideas?
>
> Sorry, error in example. Should read:
>
> datetime_string = "2015-08-12 12:01:23 PM"
> timeout = unix2datetime(Calendar.parse("yyyy-MM-dd hh:mm:ss aa",
> datetime_string).millis/1000)

As far as I am aware, there is no way to parse the AM and PM periods
with the functionality that we have in Base [1].  Currently I have
this ugly hack to handle data from a third-party database where for
some reason someone opted to store points in time in a 12-hour format.

    using Base.Dates
    ds = "2015-08-12 12:01:23 PM"
    DateTime(ds, DateFormat("yyyy-mm-dd HH:MM:SS")) - (
        contains(ds, "AM") ? Hour(12) : Hour(0))

Ideally AM/PM period handling should be added to Base and it would be
a nice and fairly atomic contribution if someone was to try to make it
happen.

    Pontus

[1]: 
https://github.com/JuliaLang/julia/blob/c2527882686e15f949b7f460ba71d5bdeeb362c0/base/dates/io.jl#L71-L81

Reply via email to