Update readme. Add some sanity guards on beginning_week
This commit is contained in:
parent
d7267a7d67
commit
6fadc548d2
2 changed files with 19 additions and 1 deletions
|
@ -710,6 +710,21 @@ There are also 0-arity versions of the above, in which `Date` is assumed to be
|
|||
"right now". For example, calling `qdate:beginning_month()` would return
|
||||
midnight on the first day of the current month.
|
||||
|
||||
### Beginning of Week
|
||||
|
||||
qdate can also do a special "beginning" case, particularly the "beginning of
|
||||
the week" calculation. This has two forms, specifically:
|
||||
|
||||
+ `beginning_week(Date)` - Assumes the beginning of the week is Monday
|
||||
(chosen because Erlang's calendar:day_of_the_week uses 1=Monday and
|
||||
7=Sunday).
|
||||
+ `beginning_week(DayOfWeek, Date)` - Calculates the beginning of the week
|
||||
based on the provided `DayOfWeek`. Valid values for DayOfWeek are 1-7,
|
||||
where 1=Monday, and 7=Sunday.
|
||||
|
||||
These all return 12am on the day that is the first day of the week of the
|
||||
provided date.
|
||||
|
||||
## Date Arithmetic
|
||||
|
||||
The current implementation of qdate's date arithmetic returns Unixtimes.
|
||||
|
|
|
@ -400,7 +400,10 @@ beginning_year(Date) ->
|
|||
beginning_week(Date) ->
|
||||
beginning_week(1, Date).
|
||||
|
||||
beginning_week(BeginningDayOfWeek, Date0) ->
|
||||
beginning_week(BeginningDayOfWeek, Date0) when
|
||||
BeginningDayOfWeek >= 1,
|
||||
BeginningDayOfWeek =< 7,
|
||||
is_integer(BeginningDayOfWeek) ->
|
||||
{DateOnly, _} = Date = to_date(Date0),
|
||||
CurDOW = calendar:day_of_the_week(DateOnly),
|
||||
if
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue