Class: Rescuetime::DateParser
- Inherits:
-
Object
- Object
- Rescuetime::DateParser
- Defined in:
- lib/rescuetime/date_parser.rb
Overview
Responsible for formatting user-inputted dates into proper Rescuetime format
Constant Summary collapse
- DATE_FORMATS =
Valid string formats for date parsing. The key is a human-readable pattern (ex. ‘yyyy-mm-dd’), and the value is the corresponding regular expression.
{ 'yyyy-mm-dd' => /\d{4}-\d{2}-\d{2}/, 'yyyy/mm/dd' => %r{\d{4}\/\d{2}\/\d{2}}, 'mm-dd-yyyy or mm/dd/yyyy' => %r{\d{2}[-\/]\d{2}[-\/]\d{4}}, 'mm-dd or mm/dd' => %r{\d{2}[-\/]\d{2}} }.freeze
Class Method Summary collapse
-
.parse(date) ⇒ String
Returns a date as a string in the correct Rescuetime API format.
Class Method Details
.parse(date) ⇒ String
Returns a date as a string in the correct Rescuetime API format
Allowed date formats:
-
Object that responds to #strftime
-
String in “YYYY-MM-DD” format
-
String in “YYYY/MM/DD” format
-
String in “MM-DD-YYYY” format
-
String in “MM/DD/YYYY” format
-
String in “MM-DD” format (defaults to current year)
-
String in “MM/DD” format (defaults to current year)
47 48 49 50 51 52 53 |
# File 'lib/rescuetime/date_parser.rb', line 47 def parse(date) if date.respond_to? :strftime date.strftime '%Y-%m-%d' else reformat_string(date) end end |