type
DateSpan
@Js
@Serializable { simple=true }
const class DateSpan : Obj
DateSpan models a span of time between two dates.
constructors
fromStr |
Construct DateSpan from Str. |
---|---|
make |
Construct a new DateSpan using a start date and period, or an explicit start date and end date. |
fields
day |
Constant for a day period. |
---|---|
end |
Inclusive end date for this span. |
month |
Constant for a month period. |
numDays |
Get number of days in this span. |
period | |
quarter |
Constant for a quarter period. |
range |
Constant for an arbitrary period. |
start |
Start date for this span. |
week |
Constant for a week period. |
year |
Constant for a month period. |
methods
contains |
Does this span inclusively contain the given Date inclusively |
---|---|
dis |
Return display name for this span. |
eachDay |
Iterate each day in this DateSpan. |
eachMonth |
Iterate each month in this date range as a range of first to last day in each month. |
equals |
Objects are equal if start, end, and period match. |
hash |
Hash is based on start/end/period. |
isDay |
Convenience for period == DateSpan.day |
isMonth |
Convenience for period == DateSpan.month |
isQuarter |
Convenience for period == DateSpan.quarter |
isRange |
Convenience for period == DateSpan.range |
isWeek |
Convenience for period == DateSpan.week |
isYear |
Convenience for period == DateSpan.year |
lastMonth |
Construct for month previous to this month |
lastQuarter |
DateSpan for 3 month quarter previous to this quarter |
lastWeek |
Construct for week previous to this week |
lastYear |
Construct for year previous to this year |
makeMonth |
Convenience for |
makeWeek |
Convenience for |
makeYear |
Convenience for |
minus |
Shift start and end by the given number of days. |
next |
Return the next DateSpan based on the period |
pastMonth |
Construct for last 30days |
pastWeek |
Construct for last 7 days as |
pastYear |
Construct for this past |
plus |
Shift start and end by the given number of days. |
prev |
Return the previous DateSpan based on the period |
thisMonth |
Construct for this month as |
thisQuarter |
DateSpan for this 3 month quarter |
thisWeek |
Construct for this week as |
thisYear |
Construct for this year |
toCode |
Return axon representation for this span. |
toSpan |
Convert this instance to a Span instance |
toStr |
Str representation is "<start>,<end|period>". |
today |
Convenience for |
yesterday |
Convenience for |
Slot Details
contains
day
const static Str day := "day"
Constant for a day period.
dis
eachDay
eachMonth
end
const Date end
Inclusive end date for this span.
equals
fromStr
static new fromStr(Str s, Bool checked := true)
Construct DateSpan from Str. This method supports parsing from the following formats:
- "<start>,<period>"
- "<start>,<end>"
- "today", "yesterday"
- "thisWeek", "thisMonth", "thisYear"
- "pastWeek", "pastMonth", "pastYear"
- "lastWeek", "lastMonth", "lastYear"
Where <start> and <end> are YYYY-MM-DD date formats and period is "day", "week", "month", or "year".
hash
virtual override Int hash()
Hash is based on start/end/period.
isDay
Bool isDay()
Convenience for period == DateSpan.day
isMonth
Bool isMonth()
Convenience for period == DateSpan.month
isQuarter
Bool isQuarter()
Convenience for period == DateSpan.quarter
isRange
Bool isRange()
Convenience for period == DateSpan.range
isWeek
Bool isWeek()
Convenience for period == DateSpan.week
isYear
Bool isYear()
Convenience for period == DateSpan.year
lastMonth
static DateSpan lastMonth()
Construct for month previous to this month 1..28-31
lastQuarter
static DateSpan lastQuarter()
DateSpan for 3 month quarter previous to this quarter
lastWeek
static DateSpan lastWeek()
Construct for week previous to this week sun..sat
(uses locale start of week)
lastYear
static DateSpan lastYear()
Construct for year previous to this year Jan-1..Dec-31
make
new make(Date start := Date.today(), Obj endOrPer := DateSpan.day)
Construct a new DateSpan using a start date and period, or an explicit start date and end date. If a period of week
, month
, quarter
, or year
is used, then the start date will be adjusted, if necessary, to the first of week, first of month, first of quarter, or first of year, respectively. If a date is passed as end, then the period is implicitly range
.
makeMonth
makeWeek
makeYear
minus
month
const static Str month := "month"
Constant for a month period.
next
DateSpan next()
Return the next DateSpan based on the period:
- day: next day
- week: next week
- month: next month
- year: next year
- range: roll start/end forward one day
numDays
const Int numDays
Get number of days in this span.
pastMonth
static DateSpan pastMonth()
Construct for last 30days today-30days..today
pastWeek
static DateSpan pastWeek()
Construct for last 7 days as today-7days..today
pastYear
static DateSpan pastYear()
Construct for this past today-365days..today
period
plus
prev
DateSpan prev()
Return the previous DateSpan based on the period:
- day: previous day
- week: previous week
- month: previous month
- quarter: previous quarter
- year: previous year
- range: roll start/end back one day
quarter
const static Str quarter := "quarter"
Constant for a quarter period.
range
const static Str range := "range"
Constant for an arbitrary period.
start
const Date start
Start date for this span.
thisMonth
static DateSpan thisMonth()
Construct for this month as 1..28-31
thisQuarter
static DateSpan thisQuarter()
DateSpan for this 3 month quarter
thisWeek
static DateSpan thisWeek()
Construct for this week as sun..sat
(uses locale start of week)
thisYear
static DateSpan thisYear()
Construct for this year Jan-1..Dec-31
toCode
Str toCode()
Return axon representation for this span.
toSpan
toStr
virtual override Str toStr()
Str representation is "<start>,<end|period>".
today
static DateSpan today()
Convenience for make(Date.today)
.
week
const static Str week := "week"
Constant for a week period.
year
const static Str year := "year"
Constant for a month period.
yesterday
static DateSpan yesterday()
Convenience for make(Date.today-1day)
.