Difference between revisions of "Oolite JavaScript Reference: Clock"
(Changed future-scripting tag to added-in-1.70) |
m (→clockString: uniform string format) |
||
(13 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
<small>'''Prototype:''' <code>Object</code></small><br /> | <small>'''Prototype:''' <code>Object</code></small><br /> | ||
− | <small>'''Subtypes:''' none | + | <small>'''Subtypes:''' none</small> |
− | + | The '''clock''' global object is used to tell the time. Apart from <code>[[#absoluteSeconds|absoluteSeconds]]</code>, all its properties have to do with [[Time scales in Oolite#Game clock time|game clock time]]. | |
− | |||
− | The '''clock''' global object is used to tell the time. Apart from <code>[[#absoluteSeconds|absoluteSeconds | ||
== Properties == | == Properties == | ||
Line 31: | Line 29: | ||
=== days === | === days === | ||
'''days''' : Number (read-only) | '''days''' : Number (read-only) | ||
− | The current time in [[Time scales in Oolite#Game clock time|game clock time]], in integer days since the epoch. If the current clock time is 2084004:17:13:42, <code> | + | The current time in [[Time scales in Oolite#Game clock time|game clock time]], in integer days since the epoch. If the current clock time is 2084004:17:13:42, <code>days</code> will be 2084004. |
=== secondsComponent === | === secondsComponent === | ||
Line 57: | Line 55: | ||
=== clockString === | === clockString === | ||
'''clockString''' : String (read-only) | '''clockString''' : String (read-only) | ||
− | The clock as displayed in the HUD, including | + | The clock as displayed in the HUD, including <code>"(adjusting)"</code> if appropriate. If the current clock time is 2084004:17:13:42 and the clock is not being adjusted, <code>clockString</code> will be <code>"2084004:17:13:42"</code>. |
=== isAdjusting === | === isAdjusting === | ||
'''isAdjusting''' : Boolean (read-only) | '''isAdjusting''' : Boolean (read-only) | ||
− | + | <code>true</code> if the clock is being adjusted, i.e. running faster than real time, as happens after witchspace jumps. | |
+ | |||
+ | === adjustedSeconds === | ||
+ | {{oolite-prop-added|1.77}} | ||
+ | '''adjustedSeconds''' : Number (read-only) | ||
+ | The adjusted current time. If the clock is not being adjusted, this will be equal to [[#seconds|seconds]]. Otherwise, it will be <code>seconds</code> plus the number of seconds remaining of the adjustment. | ||
+ | |||
+ | === legacy_scriptTimer === | ||
+ | '''legacy_scriptTimer''' : Number (read-only) | ||
+ | The current value of the legacy scriptTimer. | ||
== Methods == | == Methods == | ||
+ | === addSeconds === | ||
+ | function '''addSeconds'''(timeInSeconds : Number) | ||
+ | Adds "timeInSeconds" to the current time. Value must be positive and no greater than the equivalent of 30 days (60 * 60 * 24 * 30 = 2592000 seconds) | ||
+ | |||
=== clockStringForTime === | === clockStringForTime === | ||
− | '''clockStringForTime'''(timeInSeconds : Number) : String | + | function '''clockStringForTime'''(timeInSeconds : Number) : String |
Returns a display string for a given time, specified in seconds, in the same format as <code>[[#clockString|clockString]]</code>. For instance, to specify that something must be done within a day, you might say: | Returns a display string for a given time, specified in seconds, in the same format as <code>[[#clockString|clockString]]</code>. For instance, to specify that something must be done within a day, you might say: | ||
− | + | var message = "This task must be completed by " + clock.clockStringForTime(clock.seconds + 24 * 60 * 60) + ", or all will be lost!" | |
(Whether such a message should be specified with one-second precision is another matter. More flexible tools for date calculations may be added later.) | (Whether such a message should be specified with one-second precision is another matter. More flexible tools for date calculations may be added later.) | ||
− | [[Category:Oolite | + | [[Category:Oolite JavaScript Reference]] |
Latest revision as of 17:56, 7 November 2022
Prototype: Object
Subtypes: none
The clock global object is used to tell the time. Apart from absoluteSeconds
, all its properties have to do with game clock time.
Contents
Properties
absoluteSeconds
absoluteSeconds : Number (read-only)
The game real time clock. Roughly speaking, this is the number of seconds since the game was started, not counting time in which it was paused.
seconds
seconds : Number (read-only)
The current time in game clock time, in seconds since the epoch. If the current clock time is 2084004:17:13:42, seconds
will be at least 180058007622 and less than 180058007623.
See Also: secondsComponent
minutes
minutes : Number (read-only)
The current time in game clock time, in integer minutes since the epoch. If the current clock time is 2084004:17:13:42, minutes
will be 3000966793.
See Also: minutesComponent
hours
hours : Number (read-only)
The current time in game clock time, in integer hours since the epoch. If the current clock time is 2084004:17:13:42, hours
will be 50016113.
See Also: hoursComponent
days
days : Number (read-only)
The current time in game clock time, in integer days since the epoch. If the current clock time is 2084004:17:13:42, days
will be 2084004.
secondsComponent
secondsComponent : Number (read-only)
The second component of the clock time. If the current clock time is 2084004:17:13:42, secondsComponent
will be 42.
See Also: seconds
minutesComponent
minutesComponent : Number (read-only)
The minute component of the clock time. If the current clock time is 2084004:17:13:42, minutesComponent
will be 13.
See Also: minutes
hoursComponent
hoursComponent : Number (read-only)
The hour component of the clock time. If the current clock time is 2084004:17:13:42, hoursComponent
will be 17.
See Also: hours
daysComponent
daysComponent : Number (read-only)
Same as days
, included only for completeness.
clockString
clockString : String (read-only)
The clock as displayed in the HUD, including "(adjusting)"
if appropriate. If the current clock time is 2084004:17:13:42 and the clock is not being adjusted, clockString
will be "2084004:17:13:42"
.
isAdjusting
isAdjusting : Boolean (read-only)
true
if the clock is being adjusted, i.e. running faster than real time, as happens after witchspace jumps.
adjustedSeconds
This property was added in Oolite test release 1.77.
adjustedSeconds : Number (read-only)
The adjusted current time. If the clock is not being adjusted, this will be equal to seconds. Otherwise, it will be seconds
plus the number of seconds remaining of the adjustment.
legacy_scriptTimer
legacy_scriptTimer : Number (read-only)
The current value of the legacy scriptTimer.
Methods
addSeconds
function addSeconds(timeInSeconds : Number)
Adds "timeInSeconds" to the current time. Value must be positive and no greater than the equivalent of 30 days (60 * 60 * 24 * 30 = 2592000 seconds)
clockStringForTime
function clockStringForTime(timeInSeconds : Number) : String
Returns a display string for a given time, specified in seconds, in the same format as clockString
. For instance, to specify that something must be done within a day, you might say:
var message = "This task must be completed by " + clock.clockStringForTime(clock.seconds + 24 * 60 * 60) + ", or all will be lost!"
(Whether such a message should be specified with one-second precision is another matter. More flexible tools for date calculations may be added later.)