Skip to content

check for the existence of a specific part of a date #1747

Description

@dulyts

Is your feature request related to a problem? Please describe.
I sometimes work with ISO dates like "2015-04", but when display with toLocaleString(DateTime.DATE_SHORT) represented as 2015. 04. 01. (with 'HU' locale)

Describe the solution you'd like
Should be great a function (e.g has("day")) to validate that the parsed date contains specific part

const date = DateTime.fromISO("2015-04");
date.toLocaleString({
  year: "2-digit",
  month: date.has("month") ? "2-digit" : undefined,
  day: date.has("day") ? "2-digit" : undefined,
}); // 2015. 04.

OR
toLocaleString just skip "empty" parts

const date = DateTime.fromISO("2015-04");
date.toLocaleString(DateTime.DATE_SHORT); // 2015. 04.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions