Re: [Haskell-cafe] Help parsing dates and times

2007-10-16 Thread Thomas Hartman
dons's blog entry on parsing dates might point somewhere useful

http://cgi.cse.unsw.edu.au/~dons/blog/2006/11/12#rpn-reloaded

t.



Don Stewart [EMAIL PROTECTED] 
Sent by: [EMAIL PROTECTED]
10/15/2007 08:25 PM

To
Justin Bailey [EMAIL PROTECTED]
cc
Haskell-Cafe haskell-cafe@haskell.org
Subject
Re: [Haskell-cafe] Help parsing dates and times






jgbailey:
I am trying to parse various date and time formats using the 
parseTime
function found in (GHC 6.6.1) Data.Time.Format. The one that is 
giving me
trouble looks like this:
 
  2008-06-26T11:00:00.000-07:00
 
Specifically, the time zone offset isn't covered by the format 
parameters
given. I can almost parse it with this:
 
  %FT%X.000
 
But that doesn't take into account the -07:00 bit. I'm sure this 
has
been solved - can someone point me to the solution? Thanks in 
advance.

Is there anything in the parsedate library?


http://hackage.haskell.org/cgi-bin/hackage-scripts/package/parsedate-2006.11.10


http://hackage.haskell.org/packages/archive/parsedate/2006.11.10/doc/html/System-Time-Parse.html


-- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



---

This e-mail may contain confidential and/or privileged information. If you 
are not the intended recipient (or have received this e-mail in error) 
please notify the sender immediately and destroy this e-mail. Any 
unauthorized copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help parsing dates and times

2007-10-16 Thread Bjorn Bringert

On Oct 16, 2007, at 2:25 , Don Stewart wrote:


jgbailey:
   I am trying to parse various date and time formats using the  
parseTime
   function found in (GHC 6.6.1) Data.Time.Format. The one that is  
giving me

   trouble looks like this:

 2008-06-26T11:00:00.000-07:00

   Specifically, the time zone offset isn't covered by the format  
parameters

   given. I can almost parse it with this:

 %FT%X.000

   But that doesn't take into account the -07:00 bit. I'm sure  
this has
   been solved - can someone point me to the solution? Thanks in  
advance.


Try %z

(see http://www.haskell.org/ghc/docs/latest/html/libraries/time/Data- 
Time-Format.html#v%3AformatTime for all the format specifiers).



Is there anything in the parsedate library?

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ 
parsedate-2006.11.10
http://hackage.haskell.org/packages/archive/parsedate/ 
2006.11.10/doc/html/System-Time-Parse.html


-- Don


parsedate is obsolete, unless you have ghc  6.6.1. It was rewritten  
to become what is now the date parsing code in the time package.


/Björn



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help parsing dates and times

2007-10-16 Thread Justin Bailey
On 10/16/07, Bjorn Bringert [EMAIL PROTECTED] wrote:


 Hmm, perhaps I should clarify this: parsedate and time-1.1.1 (which
 comes with GHC 6.6.1) have different APIs. parsedate produces
 CalendarTimes, and the code in time-1.1.1 produces the new time and
 date data types. So I guess parsedate isn't actually obsolete,
 rather, it's for use with the package currently known as 'old-time'.


Given this date string:

  2008-06-26T11:00:00.000-07:00

The problem is the parseTime function in Data.Time.Format is a little too
strict. The following GHCi session shows the different behaviors. Notice how
%Z is unable to parse the time zone offset in any case. First we try
parseTime:

   :m + Data.Time System.Time.Parse System.Locale
   let dateStr = 2008-06-26T11:00:00.000-07:00
   parseTime defaultTimeLocale %FT%X.000%z dateStr :: Maybe UTCTime
  Nothing
   parseTime defaultTimeLocale %FT%X.000-%z dateStr :: Maybe UTCTime
  Nothing
   parseTime defaultTimeLocale %FT%X.000 dateStr :: Maybe UTCTime
  Nothing

Now parseCalendarTime from the parseDate package:

   parseCalendarTime defaultTimeLocale %Y-%m-%dT%H:%M:%S dateStr
  Just (CalendarTime {ctYear = 2008, ctMonth = June, ctDay = 26, ctHour =
11, ctMin = 0, ctSec = 0, ctPicosec = 0, ctWDay
= Thursday, ctYDay = 1, ctTZName = UTC, ctTZ = 0, ctIsDST = False})
   parseCalendarTime defaultTimeLocale %Y-%m-%dT%H:%M:%S.000%Z dateStr
  Nothing


Justin
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help parsing dates and times

2007-10-16 Thread Bjorn Bringert

On Oct 16, 2007, at 17:54 , Justin Bailey wrote:


On 10/16/07, Bjorn Bringert [EMAIL PROTECTED] wrote:

Hmm, perhaps I should clarify this: parsedate and time-1.1.1 (which
comes with GHC 6.6.1) have different APIs. parsedate produces
CalendarTimes, and the code in time-1.1.1 produces the new time and
date data types. So I guess parsedate isn't actually obsolete,
rather, it's for use with the package currently known as 'old-time'.

Given this date string:

  2008-06-26T11:00:00.000-07:00

The problem is the parseTime function in Data.Time.Format is a  
little too strict. The following GHCi session shows the different  
behaviors. Notice how %Z is unable to parse the time zone offset in  
any case. First we try parseTime:


   :m + Data.Time System.Time.Parse System.Locale
   let dateStr = 2008-06-26T11:00:00.000-07:00
   parseTime defaultTimeLocale %FT%X.000%z dateStr :: Maybe UTCTime
  Nothing
   parseTime defaultTimeLocale %FT%X.000-%z dateStr :: Maybe  
UTCTime

  Nothing
   parseTime defaultTimeLocale %FT%X.000 dateStr :: Maybe UTCTime
  Nothing


I guess you really want a ZonedTime here, if you want to retain the  
time zone info.


It seems like %z and %Z require 4 digits for a time zone offset,  
without a colon. This works:


 parseTime defaultTimeLocale %FT%X.000%z  
2008-06-26T11:00:00.000-0700 :: Maybe ZonedTime

Just 2008-06-26 11:00:00 -0700

Should we just add XX:XX as an alternative time zone offset format  
accepted by %z and %Z? Is this a standard format?



Now parseCalendarTime from the parseDate package:

   parseCalendarTime defaultTimeLocale %Y-%m-%dT%H:%M:%S dateStr
  Just (CalendarTime {ctYear = 2008, ctMonth = June, ctDay = 26,  
ctHour = 11, ctMin = 0, ctSec = 0, ctPicosec = 0, ctWDay

= Thursday, ctYDay = 1, ctTZName = UTC, ctTZ = 0, ctIsDST = False})
   parseCalendarTime defaultTimeLocale %Y-%m-%dT%H:%M:%S.000%Z  
dateStr

  Nothing


Hmm, ok, parsedate allows garbage at the end. I wonder what is the  
right thing to do here.


/Björn



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help parsing dates and times

2007-10-16 Thread Justin Bailey
On 10/16/07, Bjorn Bringert [EMAIL PROTECTED] wrote:


 Should we just add XX:XX as an alternative time zone offset format
 accepted by %z and %Z? Is this a standard format?


I'm not sure, but I am getting this date from Google in their XML feeds
representing calendar data. The specific element is gd:when, documented
here:

http://code.google.com/apis/gdata/elements.html#gdWhen

Hmm, ok, parsedate allows garbage at the end. I wonder what is the
 right thing to do here.


A wildcard that allowed me to say don't care would work. If parseDate was
built on regular expressions, then you could do whatever you wanted. I'm not
familiar with the C roots of this function, though, so maybe it's best to do
whatever it does.

Regardless, I'm glad to have something. I can always filter/chop the string
to remove the bits I don't care about. It's a good library.

Justin
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help parsing dates and times

2007-10-16 Thread Carl Witty
On Tue, 2007-10-16 at 09:25 -0700, Justin Bailey wrote:
 On 10/16/07, Bjorn Bringert [EMAIL PROTECTED] wrote:
 
 Should we just add XX:XX as an alternative time zone offset
 format
 accepted by %z and %Z? Is this a standard format?

Yes, this is standard; see below.

 I'm not sure, but I am getting this date from Google in their XML
 feeds representing calendar data. The specific element is gd:when,
 documented here: 
 
 http://code.google.com/apis/gdata/elements.html#gdWhen

That refers to XML Schema; the dateTime type in XML Schema is standardized here:
http://www.w3.org/TR/xmlschema-2/#dateTime
(and time zone offsets are required to have a colon in this format).

Carl Witty


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help parsing dates and times

2007-10-16 Thread Bjorn Bringert

On Oct 16, 2007, at 21:39 , Carl Witty wrote:


On Tue, 2007-10-16 at 09:25 -0700, Justin Bailey wrote:

On 10/16/07, Bjorn Bringert [EMAIL PROTECTED] wrote:

Should we just add XX:XX as an alternative time zone offset
format
accepted by %z and %Z? Is this a standard format?


Yes, this is standard; see below.


I'm not sure, but I am getting this date from Google in their XML
feeds representing calendar data. The specific element is gd:when,
documented here:

http://code.google.com/apis/gdata/elements.html#gdWhen


That refers to XML Schema; the dateTime type in XML Schema is  
standardized here:

http://www.w3.org/TR/xmlschema-2/#dateTime
(and time zone offsets are required to have a colon in this format).


Thanks, I have added this to the parser now. I can't push right now  
because of performance problems, but it'll be in darcs soon.


Now it works:

Prelude Data.Time System.Locale parseTime defaultTimeLocale %FT%T%Q% 
z 2008-06-26T11:00:00.087-07:00 :: Maybe ZonedTime

Just 2008-06-26 11:00:00.087 -0700

Note that I use %Q for the second decimals instead of .000, this  
makes it accept non-integer seconds.


/Björn



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Help parsing dates and times

2007-10-15 Thread Justin Bailey
I am trying to parse various date and time formats using the parseTime
function found in (GHC 6.6.1) Data.Time.Format. The one that is giving me
trouble looks like this:

  2008-06-26T11:00:00.000-07:00

Specifically, the time zone offset isn't covered by the format parameters
given. I can almost parse it with this:

  %FT%X.000

But that doesn't take into account the -07:00 bit. I'm sure this has been
solved - can someone point me to the solution? Thanks in advance.

Justin
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help parsing dates and times

2007-10-15 Thread Don Stewart
jgbailey:
I am trying to parse various date and time formats using the parseTime
function found in (GHC 6.6.1) Data.Time.Format. The one that is giving me
trouble looks like this:
 
  2008-06-26T11:00:00.000-07:00
 
Specifically, the time zone offset isn't covered by the format parameters
given. I can almost parse it with this:
 
  %FT%X.000
 
But that doesn't take into account the -07:00 bit. I'm sure this has
been solved - can someone point me to the solution? Thanks in advance.

Is there anything in the parsedate library?


http://hackage.haskell.org/cgi-bin/hackage-scripts/package/parsedate-2006.11.10

http://hackage.haskell.org/packages/archive/parsedate/2006.11.10/doc/html/System-Time-Parse.html

-- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe