'How to validate day and time in Erlang?
How do I validate today is business day and also current time is in between two time? I tried below code but I can only check after or before time.
is_past_15() ->
{_, {Hour, _, _}} = calendar:local_time(),
Hour >= 15.
Solution 1:[1]
validate today is business day
-module(a).
-compile(export_all).
is_business_day(Date) ->
calendar:day_of_the_week(Date) =< 5.
In the shell:
7> c(a).
a.erl:2:2: Warning: export_all flag enabled - all functions will be exported
% 2| -compile(export_all).
% | ^
{ok,a}
8> {Date, _} = calendar:local_time().
9> a:is_business_day(Date).
true
also current time is in between two time.
-module(a).
-compile(export_all).
is_between(BeginDT, EndDT, DT) ->
BeginSecs = calendar:datetime_to_gregorian_seconds(BeginDT),
EndSecs = calendar:datetime_to_gregorian_seconds(EndDT),
DTSecs = calendar:datetime_to_gregorian_seconds(DT),
(BeginSecs =< DTSecs) and (DTSecs =< EndSecs).
In the shell:
13> BeginDT = {{2021, 1, 20}, {10, 15, 0}}. %% 1/20/21 10:15:00 AM
{{2021,1,20},{10,15,0}}
14> EndDT = {{2021, 1, 20}, {10, 20, 0}}. %% 1/20/2021 10:20:00 AM
{{2021,1,20},{10,20,0}}
15> DT = {{2021, 1, 20}, {10, 17, 0}}. %% 1/20/2021 10:17:00 Am
{{2021,1,20},{10,17,0}}
16> a:is_between(BeginDT, EndDT, DT).
true
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |