This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
dev:api:railway_time_api [2019-06-20 11:04] 141.76.179.161 created |
dev:api:railway_time_api [2022-07-15 14:45] (current) maverick2797 ↷ Page moved from usage:lines:railway_time_api to dev:api:railway_time_api |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Railway Time API ====== | ====== Railway Time API ====== | ||
- | These functions are accessible at | + | This is the documentation for the [[usage: |
+ | These functions are accessible | ||
advtrains.lines.rwt.* | advtrains.lines.rwt.* | ||
+ | These functions are also accessible in the LuaATC environment at: | ||
+ | rwt.* | ||
+ | ===== Railway Time Formats ===== | ||
+ | A railway time can be represented by 3 different formats: table, string or seconds. All API functions accept any of the formats as input, and usually output in table form, unless specified otherwise. | ||
+ | ==== Table ==== | ||
+ | A railway time is represented in a table like this: | ||
+ | { | ||
+ | s=45, | ||
+ | m=23, | ||
+ | c=1, | ||
+ | } | ||
- | set_time(t) | + | ==== String ==== |
- | get_time() | + | A time string can be either in the form cc;mm;ss or mm;ss. Trailing 0's can be omitted. |
- | now() | + | mm and ss must be within 0-60. |
- | new(c, m, s) | + | |
- | copy(rwtime) | + | |
- | to_table(rwtime) | + | |
- | to_secs(rwtime, | + | |
- | to_string(rwtime_p, | + | |
- | add(t1, t2) | + | ==== Seconds ==== |
- | diff(t1, t2) | + | A simple integer value counting the seconds since 0;00;00. |
- | sub(t1, t2) | + | 5025 |
- | adj_diff(t1, | + | |
- | adjust_cycle(rwtime, | + | ===== Basic Functions ===== |
- | adjust(rwtime, | + | |
+ | now() | ||
+ | Returns current railway time in table format | ||
+ | |||
+ | new(c, m, s) | ||
+ | Creates a new railway time in table format | ||
+ | |||
+ | copy(rwtime) | ||
+ | Explicitly creates a copy of rwtime, | ||
+ | |||
+ | ===== Format conversion ===== | ||
+ | |||
+ | to_table(rwtime) | ||
+ | Explicitly converts to table format | ||
+ | |||
+ | to_secs(rwtime, [c_over]) | ||
+ | | ||
+ | c_over: if given, overrides the " | ||
+ | |||
+ | to_string(rwtime_p, | ||
+ | Explicitly converts to string format | ||
+ | no_cycle: if true, omits the cycle value, outputting a value of mm;ss | ||
+ | |||
+ | add(t1, t2) | ||
+ | Adds two railway times | ||
+ | |||
+ | diff(t1, t2) | ||
+ | Returns the time in seconds from t1 to t2 (=t2-t1) | ||
+ | Note the argument order: diff(" | ||
+ | |||
+ | sub(t1, t2) | ||
+ | Subtracts t2 from t1, result is in table form. | ||
+ | The argument order is reverse to diff(). | ||
+ | |||
+ | ===== Repeating Times ===== | ||
+ | |||
+ | Sometimes, you need to work with times like "at 15;30 every cycle" or "every two minutes" | ||
+ | |||
+ | Example: The times 05;00 25;00 45;00 would be expressed by interval 20;00, offset 05;00. | ||
+ | |||
+ | time_to_next_rpt(rwtime, | ||
+ | Returns number of seconds until this repeating time occurs the next time | ||
+ | |||
+ | time_from_last_rpt(rwtime, | ||
+ | Returns number of seconds until this repeating time occured the last time | ||
+ | |||
+ | last_rpt(rwtime, | ||
+ | Returns time when this repeating time occured the last time | ||
+ | |||
+ | next_rpt(rwtime, | ||
+ | Returns time when this repeating time occurs the next time | ||
- | get_time_until(deptime, | ||
- | time_to_next_rpt(rwtime, | ||
- | time_from_last_rpt(rwtime, | ||
- | next_rpt(rwtime, |