User Tools

Site Tools


ttrack:start

Differences

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

Link to this comparison view

Next revision
Previous revision
ttrack:start [2012/11/28 18:24]
andy created
ttrack:start [2012/12/11 12:16]
andy [Time/Date Parsing]
Line 10: Line 10:
 Basic tokens can be implemented with ''​strptime()'',​ but (in Python at least) unparsed suffix data cause an exception which means we need to know in advance how many tokens to consume. This is the reason why we need both ''<​date>''​ and a ''<​year>''​ tokens, for example. Basic tokens can be implemented with ''​strptime()'',​ but (in Python at least) unparsed suffix data cause an exception which means we need to know in advance how many tokens to consume. This is the reason why we need both ''<​date>''​ and a ''<​year>''​ tokens, for example.
  
-**''<​time>''​** +Phrases such as "next Monday"​ can be ambiguous, but they're very common so a reasonable interpretation is probably still useful. The table below shows the offset in days from the current day for each of the three phrases shown:
-  * ''​%I:%M:​%S%p''​ +
-  * ''​%I:​%M%p''​ +
-  * ''​%H:​%M:​%S''​ +
-  * ''​%H:​%M''​+
  
-**''<​date>''​** +^ Day ^ "last Wednesday"​ ^ "this Wednesday"​ ^ "next Wednesday"​ ^ 
-  * ''​%Y-%m-%d''​+^ Monday | -5d | +2d | +9d | 
 +^ Tuesday | -6d | +1d | +8d | 
 +^ Wednesday | -7d | +7d | +7d | 
 +^ Thursday | -8d | -1d | +6d | 
 +^ Friday | -9d | -2d | +5d | 
 +^ Saturday | -10d | -3d | +4d | 
 +^ Sunday | -11d | -4d | +3d |
  
-**''<​year>''​** +Note the inconsistency where "​this"​ becomes synonymous with "​next"​ for the current day --- this reflects the fact that I don't believe someone would ever say "this Wednesday"​ if they meant "​today"​.
-  * ''​%Y''​ +
-  * ''​%y'​'+
  
-**''<​month>''​** +The algorithms for each version are thus (assuming ​''<​weekday>'' ​and ''<​current weekday>'' ​have been converted to zero-based integers where Monday is zero):
-  * ''​%m''​ +
-  * ''​%b''​ +
-  * ''​%B''​ +
- +
-**''<​monthday>''​** +
-  * ''​%d''​+
  
 +  * **''"​last <​weekday>"''​**
 +    * ''<​new date> = <old date> - <current weekday> - 7 + <​weekday>''​
 +  * **''"​this <​weekday>"''​**
 +    * ''​if <​weekday>​ == <current weekday>:''​
 +      * ''<​new date> = <old date> + 7''​
 +    * ''​else:''​
 +      * ''<​new date> = <old date> - <current weekday> + <​weekday>''​
 +  * **''"​next <​weekday>"''​**
 +    * ''<​new date> = <old date> - <current weekday> + 7 + <​weekday>''​
  
 +A bare day of the week (e.g. just "​Tuesday"​) is always taken as the day of the //current// week (Monday-based),​ as opposed to some date parsing packages which regard this as synonymous with "next Tuesday"​. This means it doesn'​t quite correspond exactly with any of the last/​this/​next interpretations,​ but that's probably OK.
ttrack/start.txt · Last modified: 2012/12/11 12:16 by andy