A collection of utilities for working with the operating system.
|| -> String
Returns a string containing the name of the current operating system, e.g. "linux", "macos", "windows", etc.
|| -> Timer
Returns a timer that can be used to measure how much time has passed while a script is running.
t = os.start_timer()
# ...after some time...
print "Time taken: ${t.elapsed()}s"
t2 = os.start_timer()
print "Seconds between then and now: ${t2 - t}"
|| -> DateTime
Returns a DateTime set to the current time, using the local timezone.
|timestamp: Number| -> DateTime
Returns a DateTime set to the provided timestamp
in seconds,
using the local timezone.
|timestamp: Number, offset: Number| -> DateTime
Returns a DateTime set to the provided timestamp
in seconds,
using an offset
in seconds.
now = os.time()
# e.g. 2021-12-11 21:51:14
now.year()
# e.g. 2021
now.hour()
# e.g. 21
now.timestamp()
# e.g. 1639255874.53419
See os.time
.
|DateTime| -> Number
Returns the year component of the provided DateTime.
|DateTime| -> Number
Returns the month component of the provided DateTime.
|DateTime| -> Number
Returns the day component of the provided DateTime.
|DateTime| -> Number
Returns the hour component of the provided DateTime.
|DateTime| -> Number
Returns the minute component of the provided DateTime.
|DateTime| -> Number
Returns the nanosecond component of the provided DateTime.
|DateTime| -> Number
Returns the number of seconds since 00:00:00 UTC on January 1st 1970.
|DateTime| -> Number
Returns the DateTime's timezone offset in seconds.
|DateTime| -> String
Returns a string representing the DateTime's timezone offset in seconds.
See os.start_timer
.
|Timer, Timer| -> Number
Returns the time difference in seconds between two timers.
t1 = os.start_timer()
t2 = os.start_timer()
# t2 was started later than t1, so the time difference is positive
assert (t2 - t1) > 0
# t1 was started earlier than t2, so the time difference is negative
assert (t1 - t2) < 0
|Timer| -> Number
Returns the number of seconds that have elapsed since the timer was started.
t = os.start_timer()
# ...after some time...
print "Time taken: ${t.elapsed()}s"