User Tools

Site Tools


dev:api:railway_time_api

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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:lines:railway_time]] API. 
 +These functions are accessible for developers at:
   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'can be omitted. 
-now() +mm and ss must be within 0-60. 
-new(c, m, s+  1;23;45
-copy(rwtime) +
-to_table(rwtime) +
-to_secs(rwtime, c_over) +
-to_string(rwtime_p, no_cycle)+
  
-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, t2, thresh)+
  
-adjust_cycle(rwtime, reftime_pthresh+===== Basic Functions ===== 
-adjust(rwtime, reftimethresh)+ 
 +  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, so that changes to either object don't affect the other 
 + 
 +===== Format conversion ===== 
 + 
 +  to_table(rwtime) 
 +  Explicitly converts to table format 
 + 
 +  to_secs(rwtime[c_over]
 +  Explicitly converts to seconds format. 
 +  c_over: if given, overrides the "cycle" value to this value before conversion, while not changing rwtime 
 + 
 +  to_string(rwtime_p, [no_cycle]) 
 +  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("00;15", "00;35") = 20 
 + 
 +  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". Such expressions are called "repeating time". They are characterized by an interval ("every ii;ii") and an offset ("at oo;oo"). 
 + 
 +Example: The times 05;00 25;00 45;00 would be expressed by interval 20;00, offset 05;00. 
 + 
 +  time_to_next_rpt(rwtime, rpt_intervalrpt_offset) 
 +  Returns number of seconds until this repeating time occurs the next time 
 + 
 +  time_from_last_rpt(rwtime, rpt_interval, rpt_offset) 
 +  Returns number of seconds until this repeating time occured the last time 
 + 
 +  last_rpt(rwtime, rpt_interval, rpt_offset) 
 +  Returns time when this repeating time occured the last time 
 + 
 +  next_rpt(rwtime, rpt_interval, rpt_offset) 
 +  Returns time when this repeating time occurs the next time
  
-get_time_until(deptime, rwtime_p) 
  
-time_to_next_rpt(rwtime, rpt_interval, rpt_offset) 
-time_from_last_rpt(rwtime, rpt_interval, rpt_offset) 
-next_rpt(rwtime, rpt_interval, rpt_offset) local rwtime_s = rwt.to_secs(rwtime) local rpti_s = last_rpt(rwtime, rpt_interval, rpt_offset) 
dev/api/railway_time_api.1561021467.txt.gz · Last modified: 2019-06-20 11:04 by 141.76.179.161