DateSpan
@Js
@Serializable { simple=true }
const class DateSpan : Obj
DateSpan models a span of time between two dates.
Construct DateSpan from Str
Construct a new DateSpan using a start date and period, or an explicit start date and end date
Constant for a day period
Inclusive end date for this span
Constant for a month period
Get number of days in this span
The period
Constant for a quarter period
Constant for an arbitrary period
Start date for this span
Constant for a week period
Constant for a month period
Does this span inclusively contain the given Date inclusively
Return display name for this span
Iterate each day in this DateSpan
Iterate each month in this date range as a range of first to last day in each month
Objects are equal if start, end, and period match
Hash is based on start/end/period
Convenience for period == DateSpan.day
Convenience for period == DateSpan.month
Convenience for period == DateSpan.quarter
Convenience for period == DateSpan.range
Convenience for period == DateSpan.week
Convenience for period == DateSpan.year
Construct for month previous to this month 1..28-31
DateSpan for 3 month quarter previous to this quarter
Construct for week previous to this week sun..sat (uses locale start of week)
Construct for year previous to this year Jan-1..Dec-31
Convenience for make(Date(year, month, 1), DateSpan.month)
Convenience for make(start, DateSpan.week)
Convenience for make(Date(year, Month.jan, 1), DateSpan.year)
Shift start and end by the given number of days
Return the next DateSpan based on the period
Construct for last 30days today-30days..today
Construct for last 7 days as today-7days..today
Construct for this past today-365days..today
Shift start and end by the given number of days
Return the previous DateSpan based on the period
Construct for this month as 1..28-31
DateSpan for this 3 month quarter
Construct for this week as sun..sat (uses locale start of week)
Construct for this year Jan-1..Dec-31
Return axon representation for this span
Convert this instance to a Span instance
Str representation is ",<end|period>"
Convenience for make(Date.today)
Convenience for make(Date.today-1day)
Bool contains(Date? val)
Does this span inclusively contain the given Date inclusively
const static Str : day
Constant for a day period.
Str dis(Bool explicit := false)
Return display name for this span. If explicit is true,
display actual dates, as opposed to Today or Yesterday.
Void eachDay(|Date,Int| func)
Iterate each day in this DateSpan.
Void eachMonth(|DateSpan| f)
Iterate each month in this date range as a range of first to last day in each month.
const Date : end
Inclusive end date for this span.
virtual Bool equals(Obj? obj)
Objects are equal if start, end, and period match.
static new fromStr(Str s, Bool checked := true)
Construct DateSpan from Str. This method supports parsing from the following formats:
- ","
- ","
- "today", "yesterday"
- "thisWeek", "thisMonth", "thisYear"
- "pastWeek", "pastMonth", "pastYear"
- "lastWeek", "lastMonth", "lastYear"
Where and are YYYY-MM-DD date formats and period is "day", "week", "month", or "year".
virtual Int hash()
Hash is based on start/end/period.
Bool isDay()
Convenience for period == DateSpan.day
Bool isMonth()
Convenience for period == DateSpan.month
Bool isQuarter()
Convenience for period == DateSpan.quarter
Bool isRange()
Convenience for period == DateSpan.range
Bool isWeek()
Convenience for period == DateSpan.week
Bool isYear()
Convenience for period == DateSpan.year
static DateSpan lastMonth()
Construct for month previous to this month 1..28-31
static DateSpan lastQuarter()
DateSpan for 3 month quarter previous to this quarter
static DateSpan lastWeek()
Construct for week previous to this week sun..sat (uses locale start of week)
static DateSpan lastYear()
Construct for year previous to this year Jan-1..Dec-31
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.
static DateSpan makeMonth(Int year, Month month)
Convenience for make(Date(year, month, 1), DateSpan.month).
static DateSpan makeWeek(Date start)
Convenience for make(start, DateSpan.week).
static DateSpan makeYear(Int year)
Convenience for make(Date(year, Month.jan, 1), DateSpan.year).
@Operator
DateSpan minus(Duration d)
Shift start and end by the given number of days.
const static Str : month
Constant for a month period.
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
const Int : numDays
Get number of days in this span.
static DateSpan pastMonth()
Construct for last 30days today-30days..today
static DateSpan pastWeek()
Construct for last 7 days as today-7days..today
static DateSpan pastYear()
Construct for this past today-365days..today
const Str : period
@Operator
DateSpan plus(Duration d)
Shift start and end by the given number of days.
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
const static Str : quarter
Constant for a quarter period.
const static Str : range
Constant for an arbitrary period.
const Date : start
Start date for this span.
static DateSpan thisMonth()
Construct for this month as 1..28-31
static DateSpan thisQuarter()
DateSpan for this 3 month quarter
static DateSpan thisWeek()
Construct for this week as sun..sat (uses locale start of week)
static DateSpan thisYear()
Construct for this year Jan-1..Dec-31
Str toCode()
Return axon representation for this span.
Span toSpan(TimeZone tz)
Convert this instance to a Span instance
virtual Str toStr()
Str representation is ",<end|period>".
static DateSpan today()
Convenience for make(Date.today).
const static Str : week
Constant for a week period.
const static Str : year
Constant for a month period.
static DateSpan yesterday()
Convenience for make(Date.today-1day).