Jump to content

Wikifunctions:Type proposals/Day of the week

From Wikifunctions

Done: Day of the week (Z17402)

Summary

An enumeration for the seven days of the week.

Uses

Why should this exist?

To represent the seven days of the week, which are often used in combination with dates.

There is already a date conversion to weekday that would benefit from this type (and probably should be updated once the type is available):

What kinds of functions would be created using this?

  • How many Sundays are in a given month in a particular year?
  • Does a particular date fall on a Sunday?
  • What date is the first Tuesday in November in a particular year? (Melbourne Cup (Q1311060)⁩)
  • What date is day after the first Monday in November in a particular year? (Election Day (Q11704)⁩)
  • What day of the week is the leap day in a particular leap year?
  • Following and previous days (also, more than just the immediately following or previous)

What standard concepts, if any, does this align with?

Structure

Like all enumeration types, the day of the week consists of a single key. The key is an identity key.

Values

There are seven values. Internal representations of these numbers could start on different days. This numbering lines up with python weekday()

0. Monday 1. Tuesday 2. Wednesday 3. Thursday 4. Friday 5. Saturday 6. Sunday

but javascript starts with 0=Sunday.

Example values

Value

{
  "type": "Day of the week",
  "value": "Sunday"
}
{
  "Z1K1": "Znnnnn",
  "ZnnnnnK1": "Zmmmmm"
}

Validator

The validator ensures that:

  • the identity key points directly to a value of Day of the week

Identity

Two Days of the week are the same if their identity is the same ZID.

Converting to code

The numbers in Python and JavaScript both start at 0, but start with different days.

Python

Values start with 0=Monday.

JavaScript

Values start with 0=Sunday.

Renderer

As for all enumerations, the renderer displays the label of the value object.

Parsers

As with all enumerations, there is no parser, but a selector based on pre-defined values.

Alternatives

  • Having Python and JS start with different Days may cause confusion:
    • For either language we could decide to start on 0 or 1.
    • For either language we could decide to start the Days of the week on any day.

Comments