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.
|Number| -> DateTime
Returns a DateTime set to the provided timestamp in seconds, using the local timezone.
|Number, Number| -> DateTime
Returns a DateTime set to the provided timestamp in seconds, using a time 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| -> Integer
Returns the year component of the provided DateTime.
|DateTime| -> Integer
Returns the month component of the provided DateTime.
|DateTime| -> Integer
Returns the day component of the provided DateTime.
|DateTime| -> Integer
Returns the hour component of the provided DateTime.
|DateTime| -> Integer
Returns the minute component of the provided DateTime.
|DateTime| -> Integer
Returns the nanosecond component of the provided DateTime.
|DateTime| -> Float
Returns the number of seconds since 00:00:00 UTC on January 1st 1970.
|DateTime| -> Integer
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| -> Float
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| -> Float
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"