Package: Kernel-Dates

Class: Date

Introduction

Environment: container

A Date is an object which holds a specific point in time, from year to seconds.

Currently, there are hard-coded strings for days of the week (Monday - Sunday) as well as months in a year (January - December), and also their abbreviations.

Both days of week and months in year are indexed starting with 1 (Monday and January).

Most of the available functions use the Date class instead of a Date instance.

For example:

dv := Date daysInYear: 2024. "dv = 366"

dv := Date daysInMonth: 'February' forYear: 2020. "dv = 29"
dv := Date daysInMonth: 'October' forYear: 2022. "dv = 31"

ds := ':'.
dv := { 3. 6. 9 } do: [ :each | ds := ds + (Date shortNameOfMonth: each) + ':' ].
ds = ':Mar:Jun:Sep:'. "true"

Class Method

Category: accessing

  • abbreviationOfDay: - Answer the abbreviated name of the day of week corresponding to the given index (1=Mon, 7=Sun based).

    For example:

    dv := Date abbreviationOfDay: 2. "dv = 'Tue'"
  • dayOfWeek: - Answer the index of the day of week corresponding to the given name (1=Monday, 7=Sunday based).

    For example:

    dv := Date dayOfWeek: 'Monday'. "dv = 1"
  • daysInMonth:forYear: - Answer the number of days in the given (named) month for the given year.

    For example:

    dv := Date daysInMonth: 'February' forYear: 2024. "dv = 29"
    dv := Date daysInMonth: 'December' forYear: 2024. "dv = 31"
  • daysInYear: - Answer the number of days in the given year.

    For example:

    dv := Date daysInYear: 2020. "dv = 366"
    dv := Date daysInYear: 2021. "dv = 365"
  • indexOfMonth: - Answer the index of the month corresponding to the given name (1=January based).

    For example:

    dv := Date indexOfMonth: 'February'. "dv = 2"
  • nameOfDay: - Answer the name of the day of week corresponding to the given index (1=Monday, 7=Sunday based).

    For example:

    dv := Date nameOfDay: 4. "dv = 'Thursday'"
  • nameOfMonth: - Answer the name of the month corresponding to the given index (1=January based).

    For example:

    dv := Date nameOfMonth: 4. "dv = 'April'"
  • shortNameOfMonth: - Answer the name of the month corresponding to the given index (1=January based).

    For example:

    dv := Date shortNameOfMonth: 4. "dv = 'Apr'"

Category: instance creation

  • year:day:hour:minute:second: - Answer a Date denoting the d-th day of the given year.

    For example:

    dv := Date year: 2023 day: 32 hour: 1 minute: 0 second: 0.
    "dv = @2023-02-01T01:00:00.000000Z"
  • year:month:day:hour:minute:second: - Answer a Date denoting the d-th day of the given (as a number) month and year.

    For example:

    dv := Date year: 2023 month: 2 day: 1 hour: 1 minute: 0 second: 0.
    "dv = @2023-02-01T01:00:00.000000Z"

Last updated