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

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

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 1..28-31

lastQuarter

DateSpan for 3 month quarter previous to this quarter

lastWeek

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

lastYear

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

makeMonth

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

makeWeek

Convenience for make(start, DateSpan.week).

makeYear

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

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 today-30days..today

pastWeek

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

pastYear

Construct for this past today-365days..today

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 1..28-31

thisQuarter

DateSpan for this 3 month quarter

thisWeek

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

thisYear

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

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 make(Date.today).

yesterday

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

Slot Details

contains

Bool contains(Date? val)

Does this span inclusively contain the given Date inclusively

day

const static Str day := "day"

Constant for a day period.

dis

Str dis(Bool explicit := false)

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 override Bool equals(Obj? obj)

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

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

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 := "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 := "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

Span toSpan(TimeZone tz)

Convert this instance to a Span instance

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).