Last active
August 29, 2015 13:56
-
-
Save kostiushkin/8822879 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -module(calendar). | |
| %% API | |
| -export([is_business_time/0, is_business_time/1]). | |
| -export([is_daytime/0, is_daytime/1]). | |
| -export([is_holiday/0, is_holiday/1]). | |
| -export([is_workday/0, is_workday/1]). | |
| -export([is_in_interval/3]). | |
| %% API | |
| is_business_time() -> | |
| is_business_time(calendar:local_time()). | |
| is_business_time(FullTime) -> | |
| {Date, {H, _, _}} = FullTime, | |
| (is_workday(Date) andalso is_in_interval(H, {8, 21}, 24)). | |
| is_daytime() -> | |
| is_daytime(calendar:local_time()). | |
| is_daytime(FullTime) -> | |
| {Date, {H, _, _}} = FullTime, | |
| (is_workday(Date) andalso is_in_interval(H, {8, 21}, 24)) | |
| orelse | |
| (is_holiday(Date) andalso is_in_interval(H, {10, 21}, 24)). | |
| is_holiday() -> | |
| is_holiday(date()). | |
| is_holiday(Date) -> | |
| lists:member(calendar:day_of_the_week(Date), [6, 7]). | |
| is_workday() -> | |
| is_workday(date()). | |
| is_workday(Date) -> | |
| not is_holiday(Date). | |
| is_in_interval(Value, {Min, Max}, _NumeralBase) when Min =< Max -> | |
| (Value >= Min) andalso (Value < Max); | |
| is_in_interval(Value, {Max, Min}, NumeralBase) when Max > Min -> | |
| ((Value >= 0) andalso (Value < Min)) | |
| orelse | |
| ((Value >= Max) andalso (Value < NumeralBase)). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment