Clock class

A class that can be used instead of DateTime.

You can set a fixed time during testing by using setTestTime.

DateTimeの代わりに使うことのできるクラス。

setTestCurrentTimeを利用することで、テスト時に固定の時間を設定することができます。

Inheritance
Available extensions

Constructors

Clock(int year, [int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0, int millisecond = 0, int microsecond = 0])
A class that can be used instead of DateTime.
Clock.fromDate(DateTime date)
Creates a new Clock object from a DateTime object.
factory
Clock.fromDateTime(DateTime dateTime)
Creates a new Clock object from a DateTime object.
factory
Clock.fromMicrosecondsSinceEpoch(int microsecondsSinceEpoch, {bool isUtc = false})
Constructs a new Clock instance with the given microsecondsSinceEpoch.
factory
Clock.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, {bool isUtc = false})
Constructs a new Clock instance with the given millisecondsSinceEpoch.
factory
Clock.now()
Returns a new Clock object representing the current date and time.
factory
Clock.parse(String formattedString)
Constructs a new DateTime instance based on formattedString.
factory
Clock.timestamp()
Constructs a DateTime with the current UTC date and time.
factory
Clock.utc(int year, [int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0, int millisecond = 0, int microsecond = 0])
Constructs a DateTime instance specified in the UTC time zone.

Properties

day int
The day of the month [1..31].
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
hour int
The hour of the day, expressed as in a 24-hour clock [0..23].
no setterinherited
isUtc bool
True if this DateTime is set to UTC time.
finalinherited
microsecond int
The microsecond [0...999].
no setterinherited
microsecondsSinceEpoch int
The number of microseconds since the "Unix epoch" 1970-01-01T00:00:00Z (UTC).
no setterinherited
millisecond int
The millisecond [0...999].
no setterinherited
millisecondsSinceEpoch int
The number of milliseconds since the "Unix epoch" 1970-01-01T00:00:00Z (UTC).
no setterinherited
minute int
The minute [0...59].
no setterinherited
month int
The month [1..12].
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
second int
The second [0...59].
no setterinherited
timeZoneName String
The time zone name.
no setterinherited
timeZoneOffset Duration
The time zone offset, which is the difference between local time and UTC.
no setterinherited
weekday int
The day of the week monday..sunday.
no setterinherited
weekNumber int

Available on DateTime, provided by the DateTimeExtensions extension

Gets the ISO 8601 week number from DateTime.
no setter
year int
The year.
no setterinherited

Methods

add(Duration duration) Clock
Returns a new DateTime instance with duration added to this DateTime.
override
age([DateTime? today]) DateDuration

Available on DateTime, provided by the DateTimeExtensions extension

Returns the age at today (or current time) for the date.
compareTo(DateTime other) int
Compares this DateTime object to other, returning zero if the values are equal.
inherited
copyWith({int? year, int? month, int? day, int? hour, int? minute, int? second, int? millisecond, int? microsecond, bool? isUtc}) DateTime

Available on DateTime, provided by the DateTimeCopyWith extension

Creates a new DateTime from this one by updating individual properties.
dateToNextBirthday([DateTime? target]) DateDuration

Available on DateTime, provided by the DateTimeExtensions extension

Returns the period until the next year date at target (or current time) for a date.
difference(DateTime other) Duration
Returns a Duration with the difference when subtracting other from this DateTime.
inherited
E() String

Available on DateTime, provided by the DateTimeExtensions extension

Parse from DateTime to String corresponding to an Intl DateFormat.
format(String format) String

Available on DateTime, provided by the DateTimeExtensions extension

Parses DateTime to String by passing format corresponding to the Intl DateFormat.
HHmm() String

Available on DateTime, provided by the DateTimeExtensions extension

Parse from DateTime to String corresponding to an Intl DateFormat.
HHmmss() String

Available on DateTime, provided by the DateTimeExtensions extension

Parse from DateTime to String corresponding to an Intl DateFormat.
isAfter(DateTime other) bool
Whether this DateTime occurs after other.
inherited
isAtSameMomentAs(DateTime other) bool
Whether this DateTime occurs at the same moment as other.
inherited
isBefore(DateTime other) bool
Whether this DateTime occurs before other.
inherited
isThisDay([DateTime? dateTime]) bool

Available on DateTime, provided by the DateTimeExtensions extension

Returns true if the date is the same as a specific dateTime or the current time.
isThisHour([DateTime? dateTime]) bool

Available on DateTime, provided by the DateTimeExtensions extension

Returns true if the time is the same as a specific dateTime or the current time.
isThisMinute([DateTime? dateTime]) bool

Available on DateTime, provided by the DateTimeExtensions extension

Returns true if the minute is the same as a specific dateTime or the current time.
isThisMonth([DateTime? dateTime]) bool

Available on DateTime, provided by the DateTimeExtensions extension

Returns true if the month is the same as a specific dateTime or the current time.
isThisSecond([DateTime? dateTime]) bool

Available on DateTime, provided by the DateTimeExtensions extension

Returns true if the second is the same as a specific dateTime or the current time.
isThisYear([DateTime? dateTime]) bool

Available on DateTime, provided by the DateTimeExtensions extension

Returns true if the year is the same as a specific dateTime or the current time.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
subtract(Duration duration) Clock
Returns a new DateTime instance with duration subtracted from this DateTime.
override
toDate() DateTime

Available on DateTime, provided by the DateTimeExtensions extension

Create a new DateTime by extracting only the year and month from DateTime.
toDate() Clock

Available on Clock, provided by the ClockExtensions extension

Create a new DateTime by extracting only the year and month from DateTime.
toDateID() String

Available on DateTime, provided by the DateTimeExtensions extension

Converts from DateTime to a String of the form 20221223.
toDateTimeID() String

Available on DateTime, provided by the DateTimeExtensions extension

Converts from DateTime to a String of the form 20221223102331.
toIso8601String() String
Returns an ISO-8601 full-precision extended format representation.
inherited
toLocal() Clock
Returns this DateTime value in the local time zone.
override
toString() String
Returns a human-readable string for this instance.
inherited
toUnUtc() DateTime

Available on DateTime, provided by the DateTimeExtensions extension

Treats DateTime, which is not defined as UTC due to parsing, as UTC and converts it to local time.
toUnUtc() Clock

Available on Clock, provided by the ClockExtensions extension

Treats DateTime, which is not defined as UTC due to parsing, as UTC and converts it to local time.
toUtc() Clock
Returns this DateTime value in the UTC time zone.
override
yyyyMM() String

Available on DateTime, provided by the DateTimeExtensions extension

Parse from DateTime to String corresponding to an Intl DateFormat.
yyyyMMdd() String

Available on DateTime, provided by the DateTimeExtensions extension

Parse from DateTime to String corresponding to an Intl DateFormat.
yyyyMMddHHmm() String

Available on DateTime, provided by the DateTimeExtensions extension

Parse from DateTime to String corresponding to an Intl DateFormat.
yyyyMMddHHmmss() String

Available on DateTime, provided by the DateTimeExtensions extension

Parse from DateTime to String corresponding to an Intl DateFormat.

Operators

operator ==(Object other) bool
Whether other is a DateTime at the same moment and in the same time zone (UTC or local).
inherited

Static Methods

setTestCurrentTime(DateTime? dateTime) → void
Sets the current time for testing.
tryParse(String formattedString) Clock?
Constructs a new DateTime instance based on formattedString.
override

Constants

april → const int
April.
august → const int
August.
daysPerWeek → const int
The number of days in a week.
december → const int
December.
february → const int
February.
friday → const int
Friday.
january → const int
January.
july → const int
July.
june → const int
June.
march → const int
March.
may → const int
May.
monday → const int
Monday.
monthsPerYear → const int
The number of months in a year.
november → const int
November.
october → const int
October.
saturday → const int
Saturday.
september → const int
September.
sunday → const int
Sunday.
thursday → const int
Thursday.
tuesday → const int
Tuesday.
wednesday → const int
Wednesday.