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
The period
Constant for a week period
Constant for a month period
Constant for a month period
Start date for this span
Get number of days in this span
Constant for an arbitrary period
Inclusive end date for this span
Constant for a day period
Constant for a quarter period
Return the next DateSpan based on the period
Construct for this year Jan-1..Dec-31
Shift start and end by the given number of days
Return the previous DateSpan based on the period
Convenience for make(Date(year, month, 1), DateSpan.month)
Construct for this week as sun..sat (uses locale start of week)
Construct for month previous to this month 1..28-31
Return display name for this span
Convert this instance to a Span instance
Convenience for make(Date.today-1day)
Convenience for period == DateSpan.week
DateSpan for this 3 month quarter
DateSpan for 3 month quarter previous to this quarter
Convenience for make(Date.today)
Construct for this month as 1..28-31
Construct for last 30days today-30days..today
Str representation is "<start>,<end|period>"
Iterate each day in this DateSpan
Construct for this past today-365days..today
Convenience for period == DateSpan.quarter
Return axon representation for this span
Convenience for make(Date(year, Month.jan, 1), DateSpan.year)
Convenience for make(start, DateSpan.week)
Convenience for period == DateSpan.month
Convenience for period == DateSpan.year
Convenience for period == DateSpan.day
Construct for week previous to this week sun..sat (uses locale start of week)
Shift start and end by the given number of days
Convenience for period == DateSpan.range
Construct for last 7 days as today-7days..today
Does this span inclusively contain the given Date inclusively
Construct for year previous to this year Jan-1..Dec-31
Objects are equal if start, end, and period match
Iterate each month in this date range as a range of first to last day in each month
Hash is based on start/end/period
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)
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)
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".
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, Obj endOrPer)
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 "<start>,<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).