[Haskell-cafe] Adding to / subtracting from a LocalTime?

Adde Nilsson trialcodr at gmail.com
Sun Aug 19 00:05:57 CEST 2012


Ok, do you know of any way to add/subtract without converting to UTC and
back?

On Sat, Aug 18, 2012 at 7:53 PM, Paolino <paolo.veronelli at gmail.com> wrote:

> Hello.
>
> This is a part of a solution, with explicit TimeZone
>
> Prelude Data.Time> :t \z s t -> utcToLocalTime z $ addUTCTime
> (fromIntegral s) (localTimeToUTC z t)
> \z s t -> utcToLocalTime z $ addUTCTime (fromIntegral s) (localTimeToUTC z
> t)
>   :: Integral a => TimeZone -> a -> LocalTime -> LocalTime
>
> where the Integral arguments is in seconds, by docs
>
> regards
> paolino
>
>
>
> 2012/8/18 Adde Nilsson <trialcodr at gmail.com>
>
>> Hi.
>> How do you add to or subtract from a LocalTime?
>> I'm trying to subtract a second from a LocalTime value but the only API's
>> I can find act only on the TimeOfDay part.
>>
>> subSec :: LocalTime -> LocalTime
>> subSec (LocalTime d t) = LocalTime d $ timeToTimeOfDay ((timeOfDayToTime
>> t) - (secondsToDiffTime 1))
>>
>> I'm obviously on the wrong track as this looks way too complex for what
>> it's trying to achieve.
>> Calling with '2012-08-18 00:00:00' gives '2012-08-18 -01:59:59' which
>> isn't very helpful. How do I get to '2012-08-17 23:59:59'?
>>
>> Thanks,
>> Adde
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120819/776c5170/attachment.htm>


More information about the Haskell-Cafe mailing list