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

Robert Raschke <>
Tue Mar 15 15:56:59 CET 2011


Hi Attila,

On Tue, Mar 15, 2011 at 2:32 PM, 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.
>
>
If you want to convert the exception into a return value:

1> try calendar:datetime_to_gregorian_seconds({{2011,2,30},{1,2,3}}) catch
_:_ -> bad_datetime end.
bad_datetime

Robby


More information about the erlang-questions mailing list