Re: [Haskell-cafe] Please help : Data.Time.Format parseTime

2011-06-15 Thread Daniel Patterson
As a more general response, be careful with parsing dates, because as far as I 
can tell, it is easy to print times (with formatTime) that cannot be parsed 
(with parseTime). Specifically, if you strip the padding (of zeros or spaces) 
there is no way to parse it back in. So parseTime . formatTime is not an 
identity for anything that cuts out padding. (it results in Nothing for those 
cases). Perhaps this is because too much data is lost (doesn't seem like this 
would necessarily be the case), but it does seems like an outstanding problem 
with parseTime.

If I'm wrong, and, for example, a non-zero padded month (which occurs quite 
frequently in the world), which can easily be printed with "%-m", can be parsed 
in without pre-parsing and inserting zeros as appropriate first, I would be 
happy to hear how!

On Jun 14, 2011, at 5:32 PM, Dmitri O.Kondratiev wrote:

> Magnifique, ca marche!  Grand merci, Vincent! 
> 
> On Wed, Jun 15, 2011 at 1:16 AM, Vincent Gerard  wrote:
> Hello Dmitri,
> 
> It seems that your format pattern does not match exactly the format of
> the input, thus the parser returns Nothing.
> 
> Try the following format string which seems to work with your date:
> 
> parseTime defaultTimeLocale "%m/%d/%Y %l:%M:%S %p" ds :: Maybe
> UTCTime returns : Just 2009-10-11 19:04:28 UTC
> 
> The parsings errors in your format could come from
>  .  %D expects a 2 char year
>  .  %H expects a 0 padded hour (like 07, not 7)
> 
> Regards,
> 
> Vincent Gerard
> 
> On Wed, 15 Jun 2011 00:33:56 +0400
> "Dmitri O.Kondratiev"  wrote:
> 
> > I am trying to convert data string to time:
> >
> > import Data.Time
> > import Data.Time.Format
> > import Locale
> >
> > ds = "10/11/2009 7:04:28 PM"
> > t = parseTime defaultTimeLocale "%D %H:%M:%S  %p" ds :: Maybe UTCTime
> >
> > and get "Nothing".
> > What is wrong?
> >
> > Thanks !
> > Dmitri.
> 
> 
> 
> 
> 
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

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


Re: [Haskell-cafe] Please help : Data.Time.Format parseTime

2011-06-14 Thread Dmitri O.Kondratiev
Magnifique, ca marche!  Grand merci, Vincent!

On Wed, Jun 15, 2011 at 1:16 AM, Vincent Gerard  wrote:

> Hello Dmitri,
>
> It seems that your format pattern does not match exactly the format of
> the input, thus the parser returns Nothing.
>
> Try the following format string which seems to work with your date:
>
> parseTime defaultTimeLocale "%m/%d/%Y %l:%M:%S %p" ds :: Maybe
> UTCTime returns : Just 2009-10-11 19:04:28 UTC
>
> The parsings errors in your format could come from
>  .  %D expects a 2 char year
>  .  %H expects a 0 padded hour (like 07, not 7)
>
> Regards,
>
> Vincent Gerard
>
> On Wed, 15 Jun 2011 00:33:56 +0400
> "Dmitri O.Kondratiev"  wrote:
>
> > I am trying to convert data string to time:
> >
> > import Data.Time
> > import Data.Time.Format
> > import Locale
> >
> > ds = "10/11/2009 7:04:28 PM"
> > t = parseTime defaultTimeLocale "%D %H:%M:%S  %p" ds :: Maybe UTCTime
> >
> > and get "Nothing".
> > What is wrong?
> >
> > Thanks !
> > Dmitri.
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Please help : Data.Time.Format parseTime

2011-06-14 Thread Vincent Gerard
Hello Dmitri,

It seems that your format pattern does not match exactly the format of
the input, thus the parser returns Nothing.

Try the following format string which seems to work with your date:

parseTime defaultTimeLocale "%m/%d/%Y %l:%M:%S %p" ds :: Maybe
UTCTime returns : Just 2009-10-11 19:04:28 UTC

The parsings errors in your format could come from 
 .  %D expects a 2 char year
 .  %H expects a 0 padded hour (like 07, not 7)

Regards,

Vincent Gerard

On Wed, 15 Jun 2011 00:33:56 +0400
"Dmitri O.Kondratiev"  wrote:

> I am trying to convert data string to time:
> 
> import Data.Time
> import Data.Time.Format
> import Locale
> 
> ds = "10/11/2009 7:04:28 PM"
> t = parseTime defaultTimeLocale "%D %H:%M:%S  %p" ds :: Maybe UTCTime
> 
> and get "Nothing".
> What is wrong?
> 
> Thanks !
> Dmitri.


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


Re: [Haskell-cafe] Please help : Data.Time.Format parseTime

2011-06-14 Thread Henk-Jan van Tuyl
On Tue, 14 Jun 2011 22:33:56 +0200, Dmitri O.Kondratiev  
 wrote:



I am trying to convert data string to time:

import Data.Time
import Data.Time.Format
import Locale

ds = "10/11/2009 7:04:28 PM"
t = parseTime defaultTimeLocale "%D %H:%M:%S  %p" ds :: Maybe UTCTime

and get "Nothing".
What is wrong?


According to the documentation[0], %D expects a two digit year.

Regards,
Henk-Jan van Tuyl

[0]  
http://hackage.haskell.org/packages/archive/time/latest/doc/html/Data-Time-Format.html#v:formatTime



--
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--

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


[Haskell-cafe] Please help : Data.Time.Format parseTime

2011-06-14 Thread Dmitri O.Kondratiev
I am trying to convert data string to time:

import Data.Time
import Data.Time.Format
import Locale

ds = "10/11/2009 7:04:28 PM"
t = parseTime defaultTimeLocale "%D %H:%M:%S  %p" ds :: Maybe UTCTime

and get "Nothing".
What is wrong?

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