Still have trouble iterating days (<br>I have: <br>ds1 = "10/11/2009 7:04:28 PM"<br>ds2 = "10/17/2009 8:48:29 AM"<br>t1 = readTime defaultTimeLocale "%m/%d/%Y %l:%M:%S %p" ds1 :: UTCTime<br>t2 = readTime defaultTimeLocale "%m/%d/%Y %l:%M:%S %p" ds2 :: UTCTime<br>
dif = diffUTCTime t2 t1<br><div class="gmail_quote"><br>I need to:<br>1) Find how many complete days elapsed between t1 and t2<br>2) Find UTCTime for a moment 6 days after t1, in other words time equal to t1 + 6 * 24 hours.<br>
<br>Questions:<br>1) Is there any library function that will convert (diff = diffUTCTime t2 t1) to a data structure similar to a tuple (days, hours, mins, secs) where 'days' is a whole number of days in my 'diff'' interval, and similar for 'hours', 'mins' and 'secs' in the tuple above?<br>
2) What is the 'right way' of adding days to UTCTime? Should I add just equivalent number of seconds or should I convert UTCTime to Data.Time.Calendar.Day type first and then use 'addDays' function?<br>3) How to convert UTCTime to Data.Time.Calendar.Day and back to UTCTime?<br>
<br>Thanks!<br><br><br>On Wed, Jun 15, 2011 at 12:55 PM, Dmitri O.Kondratiev <span dir="ltr"><<a href="mailto:dokondr@gmail.com">dokondr@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>Hi, Yitz!<br>Your example puts scattered around pieces in place, thanks a lot! <br><div><div></div><div class="h5"><br>On Wed, Jun 15, 2011 at 9:49 AM, Yitzchak Gale <span dir="ltr"><<a href="mailto:gale@sefer.org" target="_blank">gale@sefer.org</a>></span> wrote:<br>
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Dmitri O.Kondratiev wrote:<br>
> It would also help to see a simple example of parsing "10/11/2009 7:04:28<br>
> PM" to time and date objects.<br>
<br>
</div>Let's assume that 10/11/2009 means October 11, as in the U.S.<br>
Then you can use:<br>
<br>
import System.Locale (defaultTimeLocale)<br>
import Data.Time<br>
<br>
thatMoment :: Maybe UTCTime<br>
thatMoment = parseTime defaultTimeLocale "%m/%d/%Y %l:%M:%S %p"<br>
<div>"10/11/2009 7:04:28 PM"<br>
<br>
</div>Then use diffUTCTime to subtract two UTCTime and<br>
get the amount of time between them. The resulting object<br>
can then be used as if it is a regular floating point number<br>
in units of seconds, or you can use the functions in Data.Time<br>
that treat it specially as an amount of time.<br>
<br>
There are many options for the format string and locale that will<br>
affect how the date is parsed - the order of month and day,<br>
leading zeros or leading spaces, upper case or lower case AM or PM<br>
(or 24-hour clock), etc. You can also get different behavior on<br>
parsing failure by using readTime or readsTime instead of parseTime.<br>
<br>
For details, see:<br>
<br>
<a href="http://www.haskell.org/ghc/docs/7.0.3/html/libraries/time-1.2.0.3/Data-Time-Format.html" target="_blank">http://www.haskell.org/ghc/docs/7.0.3/html/libraries/time-1.2.0.3/Data-Time-Format.html</a><br>
<a href="http://www.haskell.org/ghc/docs/7.0.3/html/libraries/old-locale-1.0.0.2/System-Locale.html#t:TimeLocale" target="_blank">http://www.haskell.org/ghc/docs/7.0.3/html/libraries/old-locale-1.0.0.2/System-Locale.html#t:TimeLocale</a><br>
<a href="http://www.haskell.org/ghc/docs/7.0.3/html/libraries/old-locale-1.0.0.2/src/System-Locale.html#TimeLocale" target="_blank">http://www.haskell.org/ghc/docs/7.0.3/html/libraries/old-locale-1.0.0.2/src/System-Locale.html#TimeLocale</a><br>
<br>
As an example of modifying the locale, let's say you want to use "a" and "p"<br>
instead of "AM" and "PM", as is customary in some parts of the world.<br>
Then you can say:<br>
<br>
myLocale = defaultTimeLocale {amPm = ("a","p")}<br>
<br>
and then use myLocale instead of defaultTimeLocale.<br>
<br>
Hope this helps,<br>
Yitz<br>
</blockquote></div><br><br clear="all"><br><br>
</div></div></blockquote></div><br><br>