[erlang-questions] Time range event filtering

Jesse Gumm <>
Tue Sep 10 22:22:14 CEST 2013


Hi Mark,

You could give qdate[1] a whirl. While it doesn't yet have date/time
comparison functions built-in yet[2], implementing those comparisons
is relatively trivial in your app. It can convert from several formats
and take into account timezones either in strings ("2013-09-10 9pm
CDT") or as a tuple ({SomeDate, Timezone}).

TZ = "CDT",
>From = {{2013,9,10},{9,0,0}},
To = {{2013,9,10},{21,0,0}},
FromTS = qdate:to_now({From, TZ}),
ToTS = qdate:to_now({To, TZ}),
Now = erlang:now(),
IsInRange = Now >= FromTS andalso Now =< ToTS.

-Jesse

[1] https://github.com/choptastic/qdate
[2] https://github.com/choptastic/qdate/issues/2

On Tue, Sep 10, 2013 at 2:34 PM, Mark Allen <> wrote:
> At $DAYJOB, my team is working on a project where we need to compute a time range (like 9am to 9pm in a specified timezone) and see if erlang:now() is in that time range and take a different action if the bool is true or false.
>
> Are there any good libraries for working with time ranges like this?  I wanted to ask before we re-invent the wheel.  I didn't find anything especially appropriate on a cursory web search.
>
> Thanks.
>
> Mark
>
> Mark Allen
> Sr Software Developer
> Alert Logic
>
> E: 
>
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions



-- 
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm


More information about the erlang-questions mailing list