Thanks Philip and Roger,<br><br>I think I&#39;ll use...<br><br>&nbsp; floor $ toRational td<br><br>...although I could have sworn that didn&#39;t work last night. I don&#39;t see that TimeDiff has an instance of RealFrac, where floor is defined, though it does have a instances of Real and Fractional.<br>
<br>Yes, the numeric classes are a bit hard to follow. Especially confusing is the conversions. I&#39;m thinking of making a multiparameter Coercible class, with a coerce function, to help address that.<br><br>- Lyle<br><br>
<div class="gmail_quote">On Wed, Nov 12, 2008 at 9:43 AM, Philip Weaver <span dir="ltr">&lt;<a href="mailto:philip.weaver@gmail.com">philip.weaver@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><br><div class="gmail_quote">2008/11/12 Lyle Kopnicky <span dir="ltr">&lt;<a href="mailto:lists@qseep.net" target="_blank">lists@qseep.net</a>&gt;</span><div><div></div><div class="Wj3C7c"><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<span style="border-collapse: collapse;"><div>Hi folks,</div><div><br></div><div>I had some code using the oldtime package, and want to convert it to use the time package.</div><div><br></div><div>
One of the things I need to do is calculate the number of seconds since midnight. The easy part is getting a TimeDiff result:</div><div><br></div><div>utc &lt;- getCurrentTime</div><div>tz &lt;- getCurrentTimeZone</div><div>


let td = timeOfDayToTime $ localTimeOfDay $ utcToLocalTime tz utc</div><div><br></div><div>Now td is a TimeDiff representation of the number of seconds since midnight. It prints nicely, but I&#39;m having a heck of a time figuring out how to truncate it to an Int.</div>


<div><br></div><div>The floor function is only supported by the RealFrac class. Although TimeDiff has an instance of RealFrac and Fractional, it doesn&#39;t have an instance of RealFrac. I looked up the various to* and from* functions and have come up short. fromEnum yields an Int but it&#39;s the wrong value.&nbsp;I know I could use show and then use readS to get an Integer, or use formatTime (and reparse that), but that&#39;s a hack.</div>


<div><br></div><div>I can convert it to a TimeOfDay which gives me hours, minutes, and seconds, but then I have to do arithmetic on it, and the seconds are of type Pico, which I can&#39;t call floor on either. I can convert it to a Rational via timeOfDayToDayFraction, but a TimeDiff is already a Rational those don&#39;t have floor.</div>


<div><br></div><div>What am I missing? There has got to be an easy way to count seconds!</div><div></div></span></blockquote></div></div><div><br>Well, you could always (read . takeWhile (not . (==&#39;.&#39;)) . show), but here&#39;s a better way:<br>

<br>&nbsp;&nbsp; let x = toRational td<br>&nbsp;&nbsp; in numerator x `div` denominator x<br><br>This was just the first thing I could come up with.&nbsp; I bet there&#39;s a nicer way.<br><br>- Phil<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<span style="border-collapse: collapse;"><div><br></div><div>Thanks,</div><div>Lyle</div><div><br></div></span>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>
</blockquote></div><br>