Module: AEMO::Time
- Defined in:
- lib/aemo/time.rb
Overview
- AEMO::Time
-
provides time helpers for AEMO services.
Constant Summary collapse
- NEMTIMEZONE =
'Australia/Brisbane'
- TIMESTAMP14 =
'%Y%m%d%H%M%S'
- TIMESTAMP14_PATTERN =
/^\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}$/
- TIMESTAMP12 =
'%Y%m%d%H%M'
- TIMESTAMP12_PATTERN =
/^\d{4}\d{2}\d{2}\d{2}\d{2}$/
- TIMESTAMP8 =
'%Y%m%d'
- TIMESTAMP8_PATTERN =
/^\d{4}\d{2}\d{2}$/
Class Method Summary collapse
-
.format_timestamp12(time) ⇒ String
Format a time to a timestamp 12.
-
.format_timestamp14(time) ⇒ String
Format a time to a timestamp 14.
-
.format_timestamp8(time) ⇒ String
Format a time to a timestamp 8.
-
.parse_timestamp12(string) ⇒ Time
Parse a 12 character timestamp.
-
.parse_timestamp14(string) ⇒ Time
Parse a 14 character timestamp.
-
.parse_timestamp8(string) ⇒ Time
Parse an 8 character date.
-
.valid_timestamp12?(string) ⇒ Boolean
Check if a string is a valid timestamp 12.
-
.valid_timestamp14?(string) ⇒ Boolean
Check if a string is a valid timestamp 14.
-
.valid_timestamp8?(string) ⇒ Boolean
Check if a string is a valid timestamp 8.
Class Method Details
.format_timestamp12(time) ⇒ String
Format a time to a timestamp 12.
32 33 34 |
# File 'lib/aemo/time.rb', line 32 def (time) time.in_time_zone(NEMTIMEZONE).strftime(TIMESTAMP12) end |
.format_timestamp14(time) ⇒ String
Format a time to a timestamp 14.
24 25 26 |
# File 'lib/aemo/time.rb', line 24 def (time) time.in_time_zone(NEMTIMEZONE).strftime(TIMESTAMP14) end |
.format_timestamp8(time) ⇒ String
Format a time to a timestamp 8.
40 41 42 |
# File 'lib/aemo/time.rb', line 40 def (time) time.in_time_zone(NEMTIMEZONE).strftime(TIMESTAMP8) end |
.parse_timestamp12(string) ⇒ Time
Parse a 12 character timestamp.
59 60 61 62 63 |
# File 'lib/aemo/time.rb', line 59 def (string) raise AEMO::TimeError unless string.match(TIMESTAMP12_PATTERN) ::Time.find_zone(NEMTIMEZONE).strptime(string, TIMESTAMP12) end |
.parse_timestamp14(string) ⇒ Time
Parse a 14 character timestamp.
49 50 51 52 53 |
# File 'lib/aemo/time.rb', line 49 def (string) raise AEMO::TimeError unless string.match(TIMESTAMP14_PATTERN) ::Time.find_zone(NEMTIMEZONE).strptime(string, TIMESTAMP14) end |
.parse_timestamp8(string) ⇒ Time
Parse an 8 character date.
69 70 71 72 73 |
# File 'lib/aemo/time.rb', line 69 def (string) raise AEMO::TimeError unless string.match(TIMESTAMP8_PATTERN) ::Time.find_zone(NEMTIMEZONE).strptime(string, TIMESTAMP8) end |
.valid_timestamp12?(string) ⇒ Boolean
Check if a string is a valid timestamp 12.
91 92 93 94 95 96 97 |
# File 'lib/aemo/time.rb', line 91 def (string) (string) true rescue AEMO::TimeError false end |