class

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 period

The period

week

Constant for a week period

month

Constant for a month period

year

Constant for a month period

start

Start date for this span

numDays

Get number of days in this span

range

Constant for an arbitrary period

end

Inclusive end date for this span

day

Constant for a day period

quarter

Constant for a quarter period

methods next

Return the next DateSpan based on the period

thisYear

Construct for this year Jan-1..Dec-31

minus

Shift start and end by the given number of days

prev

Return the previous DateSpan based on the period

makeMonth

Convenience for make(Date(year, month, 1), DateSpan.month)

thisWeek

Construct for this week as sun..sat (uses locale start of week)

lastMonth

Construct for month previous to this month 1..28-31

dis

Return display name for this span

toSpan

Convert this instance to a Span instance

yesterday

Convenience for make(Date.today-1day)

isWeek

Convenience for period == DateSpan.week

thisQuarter

DateSpan for this 3 month quarter

lastQuarter

DateSpan for 3 month quarter previous to this quarter

today

Convenience for make(Date.today)

thisMonth

Construct for this month as 1..28-31

pastMonth

Construct for last 30days today-30days..today

toStr

Str representation is "<start>,<end|period>"

eachDay

Iterate each day in this DateSpan

pastYear

Construct for this past today-365days..today

isQuarter

Convenience for period == DateSpan.quarter

toCode

Return axon representation for this span

makeYear

Convenience for make(Date(year, Month.jan, 1), DateSpan.year)

makeWeek

Convenience for make(start, DateSpan.week)

isMonth

Convenience for period == DateSpan.month

isYear

Convenience for period == DateSpan.year

isDay

Convenience for period == DateSpan.day

lastWeek

Construct for week previous to this week sun..sat (uses locale start of week)

plus

Shift start and end by the given number of days

isRange

Convenience for period == DateSpan.range

pastWeek

Construct for last 7 days as today-7days..today

contains

Does this span inclusively contain the given Date inclusively

lastYear

Construct for year previous to this year Jan-1..Dec-31

equals

Objects are equal if start, end, and period match

eachMonth

Iterate each month in this date range as a range of first to last day in each month

hash

Hash is based on start/end/period

contains Bool contains(Date? val)

Does this span inclusively contain the given Date inclusively

day const static Str : day

Constant for a day period.

dis Str dis(Bool explicit)

Return display name for this span. If explicit is true, display actual dates, as opposed to Today or Yesterday.

eachDay Void eachDay(|Date,Int| func)

Iterate each day in this DateSpan.

eachMonth Void eachMonth(|DateSpan| f)

Iterate each month in this date range as a range of first to last day in each month.

end const Date : end

Inclusive end date for this span.

equals virtual Bool equals(Obj? obj)

Objects are equal if start, end, and period match.

fromStr 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".

hash virtual 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, 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.

makeMonth static DateSpan makeMonth(Int year, Month month)

Convenience for make(Date(year, month, 1), DateSpan.month).

makeWeek static DateSpan makeWeek(Date start)

Convenience for make(start, DateSpan.week).

makeYear static DateSpan makeYear(Int year)

Convenience for make(Date(year, Month.jan, 1), DateSpan.year).

minus @Operator
DateSpan minus(Duration d)

Shift start and end by the given number of days.

month const static Str : 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 const Str : period

The period: day, week, month, quarter, year, or range.

plus @Operator
DateSpan plus(Duration d)

Shift start and end by the given number of days.

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

Constant for a quarter period.

range const static Str : 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 Span toSpan(TimeZone tz)

Convert this instance to a Span instance

toStr virtual Str toStr()

Str representation is "<start>,<end|period>".

today static DateSpan today()

Convenience for make(Date.today).

week const static Str : week

Constant for a week period.

year const static Str : year

Constant for a month period.

yesterday static DateSpan yesterday()

Convenience for make(Date.today-1day).

Haxall 4.0.5 ∙ 24-Feb-2026 14:33 EST