SkySpark by SkyFoundry

const class proj::DateSpan

sys::Obj
  proj::DateSpan

@Js
@Serializable { simple=true }

DateSpan models a span of time between two dates.

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

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

const static DateSpan lastMonth()

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

lastWeek

const static DateSpan lastWeek()

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

lastYear

const 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

const static DateSpan makeMonth(Int year, Month month)

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

makeWeek

const static DateSpan makeWeek(Date start)

Convenience for make(start, DateSpan.week).

makeYear

const 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

const static DateSpan pastMonth()

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

pastWeek

const static DateSpan pastWeek()

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

pastYear

const 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

const static DateSpan thisMonth()

Construct for this month as 1..28-31

thisWeek

const static DateSpan thisWeek()

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

thisYear

const static DateSpan thisYear()

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

toCode

Str toCode()

Return axon representation for this span.

toStr

virtual override Str toStr()

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

today

const 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

const static DateSpan yesterday()

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