License:
BSD style: see license.txtVersion:
mid 2005: Initial release Apr 2007: heavily reshaped Dec 2007: moved to tango.timeAuthor:
John Chapman, Kris, scheivguyNote:
nobody should change this struct without really good reason as it is required to be a part of some interfaces. It should be treated as a builtin type. Also note that there is deliberately no opCall constructor here, since it tends to produce too much overhead. If you wish to build a TimeSpan struct from a ticks value, use D's builtin ability to create a struct with given member values (See the description of ticks() for an example of how to do this).Example:
1 2 3 | Time start = Clock.now; Thread.sleep(0.150); Stdout.formatln("slept for {} ms", (Clock.now-start).millis); |
See Also:
tango.core.Thread, tango.time.Clock
1 2 | long ticks = myTimeSpan.ticks; TimeSpan copyOfMyTimeSpan = TimeSpan(ticks); |
Params:
t | A TimeSpan value to add |
Returns:
A TimeSpan value that is the sum of this instance and t.Params:
t | A TimeSpan value to add |
Returns:
a copy of this instance after adding t.Params:
t | A TimeSpan to subtract |
Returns:
A new timespan which is the difference between this instance and tParams:
t | A TimeSpan to subtract |
Returns:
A copy of this instance after subtracting t.Params:
v | A multiplier to use for scaling this time span. |
Returns:
A new TimeSpan that is scaled by vParams:
v | A multipler to use for scaling |
Returns:
A copy of this instance after scalingParams:
v | A divisor to use for scaling this time span. |
Returns:
A new TimeSpan that is divided by vParams:
v | A multipler to use for dividing |
Returns:
A copy of this instance after dividingParams:
t | A divisor used for dividing |
Returns:
The result of integer division between this instance and t.Returns:
The negative equivalent to this time spanNote:
this may incur loss of data because nanoseconds cannot represent the range of data a TimeSpan can represent.Returns:
The number of nanoseconds that this TimeSpan represents.Returns:
The number of microseconds that this TimeSpan represents.Returns:
The number of milliseconds that this TimeSpan represents.Returns:
The number of seconds that this TimeSpan represents.Returns:
The number of minutes that this TimeSpan represents.Returns:
The number of hours that this TimeSpan represents.Returns:
The number of days that this TimeSpan represents.Note:
This may cause a loss of precision as a double cannot exactly represent some fractional values.Returns:
An interval representing the seconds and fractional seconds that this TimeSpan represents.Returns:
the TimeOfDay this TimeSpan represents.Note:
This may cause a loss of data since a TimeSpan's resolution is in 100ns increments.Params:
value | The number of nanoseconds. |
Returns:
A TimeSpan representing the given number of nanoseconds.Params:
value | The number of microseconds. |
Returns:
A TimeSpan representing the given number of microseconds.Params:
value | The number of milliseconds. |
Returns:
A TimeSpan representing the given number of milliseconds.Params:
value | The number of seconds. |
Returns:
A TimeSpan representing the given number of seconds.Params:
value | The number of minutes. |
Returns:
A TimeSpan representing the given number of minutes.Params:
value | The number of hours. |
Returns:
A TimeSpan representing the given number of hours.Params:
value | The number of days. |
Returns:
A TimeSpan representing the given number of days.Params:
value | The interval to convert in seconds. |
Returns:
A TimeSpan representing the given interval.Remarks:
Time represents dates and times between 12:00:00 midnight on January 1, 10000 BC and 11:59:59 PM on December 31, 9999 AD. Time values are measured in 100-nanosecond intervals, or ticks. A date value is the number of ticks that have elapsed since 12:00:00 midnight on January 1, 0001 AD in the Gregorian calendar. Negative Time values are offsets from that same reference point, but backwards in history. Time values are not specific to any calendar, but for an example, the beginning of December 31, 1 BC in the Gregorian calendar is Time.epoch - TimeSpan.days(1).writing:
1 2 | long ticks = myTime.ticks; Time copyOfMyTime = Time(ticks); |
Returns:
A long represented by the time of this instance.Params:
value | A Time _value. |
Returns:
true if both instances are equal; otherwise, falseParams:
t | A TimeSpan value. |
Returns:
A Time that is the sum of this instance and t.Params:
t | A TimeSpan value. |
Returns:
The current Time instance, with t added to the time.Params:
t | A TimeSpan value. |
Returns:
A Time whose value is the value of this instance minus the value of t.Params:
t | A Time value. |
Returns:
A TimeSpan which represents the difference between this and t.Params:
t | A TimeSpan value. |
Returns:
The current Time instance, with t subtracted from the time.Returns:
A new Time instance with the same date as this instance, but with the time truncated.Returns:
A TimeOfDay representing the fraction of the day elapsed since midnight.Returns:
A TimeSpan representing this Time.Returns:
A TimeSpan representing this Time as Unix time.
1 2 | auto unixTime = Clock.now.unix.seconds; auto javaTime = Clock.now.unix.millis; |
1 2 3 4 5 | auto time = Clock.now.time; assert (time.millis < 1000); assert (time.seconds < 60); assert (time.minutes < 60); assert (time.hours < 24); |
Params:
hours | number of hours since midnight |
minutes | number of minutes into the hour |
seconds | number of seconds into the minute |
millis | number of milliseconds into the second |
Returns:
a TimeOfDay representing the given time fields.Note:
There is no verification of the range of values, or normalization made. So if you pass in larger values than the maximum value for that field, they will be stored as that value.example:
1 2 3 4 5 | auto tod = TimeOfDay(100, 100, 100, 10000); assert(tod.hours == 100); assert(tod.minutes == 100); assert(tod.seconds == 100); assert(tod.millis == 10000); |
Params:
ticks | ticks representing a Time value. This is normalized so that it represent a time of day (modulo-24 etc) |
Returns:
a TimeOfDay value that corresponds to the time of day of the given number of ticks.Returns:
a TimeOfDay representing the field values.Note:
that fields are not checked against a valid range, so setting 60 for minutes is allowed, and will just add 1 to the hour component, and set the minute component to 0. The result is normalized, so the hours wrap. If you pass in 25 hours, the resulting TimeOfDay will have a hour component of 1.