Date class

An RFC 3339 full-date (YYYY-MM-DD): a calendar day, with no time and no timezone.

Deliberately a plain year/month/day value class rather than a wrapper around DateTime. A DateTime is a specific instant, so any date backed by one leaks a timezone bug that no normalization can close: stored as UTC midnight it reads as the previous day under .toLocal() in negative-offset zones; stored as local midnight it breaks the wire round-trip and hits the DST "no midnight" gap. A date is not an instant, so this type does not hold one. Converting to a DateTime therefore forces you to choose the timezone explicitly — toUtcDateTime / toLocalDateTime, no silent default.

Dart core has no date-only type (see https://github.com/dart-lang/sdk/issues/49426); if it gains one, this becomes an alias for it.

Implemented types
Annotations
  • @immutable

Constructors

Date(int year, int month, int day)
const
Date.fromJson(String json)
Parses an RFC 3339 full-date. Only the calendar components are read — the string is never treated as an instant — so the result is timezone-free.
factory

Properties

day int
final
hashCode int
The hash code for this object.
no setteroverride
month int
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
year int
final

Methods

compareTo(Date other) int
Zero-padded toJson compares lexicographically == chronologically.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() String
toLocalDateTime() DateTime
This date at midnight in the local timezone.
toString() String
A string representation of this object.
override
toUtcDateTime() DateTime
This date at midnight UTC. You must pick the timezone; no silent default.

Operators

operator ==(Object other) bool
The equality operator.
override

Static Methods

maybeFromJson(String? json) Date?
Nullable convenience for optional fields.