Still have trouble iterating days (<br>I have: <br>ds1 = &quot;10/11/2009 7:04:28 PM&quot;<br>ds2 = &quot;10/17/2009 8:48:29 AM&quot;<br>t1 = readTime defaultTimeLocale &quot;%m/%d/%Y %l:%M:%S %p&quot; ds1 :: UTCTime<br>t2 = readTime defaultTimeLocale &quot;%m/%d/%Y %l:%M:%S %p&quot; 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 &#39;days&#39; is a whole number of days in my &#39;diff&#39;&#39; interval, and similar for &#39;hours&#39;, &#39;mins&#39; and &#39;secs&#39; in the tuple above?<br>
2) What is the &#39;right way&#39; 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 &#39;addDays&#39; 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">&lt;<a href="mailto:dokondr@gmail.com">dokondr@gmail.com</a>&gt;</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">&lt;<a href="mailto:gale@sefer.org" target="_blank">gale@sefer.org</a>&gt;</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>
&gt; It would also help to see a simple example of parsing &quot;10/11/2009 7:04:28<br>
&gt; PM&quot; to  time and date objects.<br>
<br>
</div>Let&#39;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 &quot;%m/%d/%Y %l:%M:%S %p&quot;<br>
<div>&quot;10/11/2009 7:04:28 PM&quot;<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&#39;s say you want to use &quot;a&quot; and &quot;p&quot;<br>
instead of &quot;AM&quot; and &quot;PM&quot;, as is customary in some parts of the world.<br>
Then you can say:<br>
<br>
myLocale = defaultTimeLocale {amPm = (&quot;a&quot;,&quot;p&quot;)}<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>