[erlang-questions] add a time interval to a timestamp

Ralf P. Gans Ralf.Gans@REDACTED
Tue Mar 15 15:53:25 CET 2011


Hi,

I'm very new to erlang, but isn't the exception the validation?
Isn't the exception catchable?

It's what I would do in C++ or Java.

Or am I thinking the wrong way?

Cheers, Ralf

On 15.03.2011, at 15:32, Attila Rajmund Nohl wrote:

> Hello!
> 
> Unfortunately the calendar:* functions crash on wrong input:
> 
> 1> calendar:datetime_to_gregorian_seconds({{2011,2,30},{1,2,3}}).
> ** exception error: no true branch found when evaluating an if expression
>     in function  calendar:date_to_gregorian_days/3
>     in call from calendar:datetime_to_gregorian_seconds/1
> 
> So if the input cannot be trusted, there's still some validation to be done.
> 
> 2011/3/15, Harsh J <qwertymaniac@REDACTED>:
>> Hello,
>> 
>> How about handling this with seconds since year 0?
>> calendary:datetime_to_gregorian_seconds to get seconds, adding up this
>> integer in seconds as you need and converting back to datetime with
>> calendary:gregorian_seconds_to_datetime.
>> 
>> On Tue, Mar 15, 2011 at 4:24 PM, Loris Fichera <loris.fichera@REDACTED>
>> wrote:
>>> Hello everybody,
>>> 
>>> Say I want to write a function that takes as input a timestamp (in the
>>> form {{y,m,d}, {h,m,s}} ) and returns another timestamp, obtained by
>>> adding a certain amount of {hours, minutes, seconds} to the input.
>> 
>> --
>> Harsh J
>> http://harshj.com
>> 
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>> 
>> 
> 
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
> 



More information about the erlang-questions mailing list