Class: Cease::Eviction::Command::DateTime
- Inherits:
-
Object
- Object
- Cease::Eviction::Command::DateTime
- Extended by:
- Forwardable
- Defined in:
- lib/cease/eviction/command/date_time.rb
Defined Under Namespace
Classes: BadOptionsError
Constant Summary collapse
- DEFAULT_TIMEZONE =
'UTC'.freeze
- TIMEZONE_NAME_MAPPING =
{ "UTC" => "Etc/UTC", "PST" => "America/Los_Angeles", "MTZ" => "America/Denver", "CST" => "America/Chicago", "EST" => "America/New_York" }.freeze
- TIMEZONE_KEY =
"timezone".freeze
Instance Method Summary collapse
- #guess? ⇒ Boolean
-
#initialize(comment, date_time, options) ⇒ DateTime
constructor
A new instance of DateTime.
- #parsed_in_timezone ⇒ TZ::DateTimeWithOffset?
- #tz ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(comment, date_time, options) ⇒ DateTime
Returns a new instance of DateTime.
27 28 29 30 31 |
# File 'lib/cease/eviction/command/date_time.rb', line 27 def initialize(comment, date_time, ) @comment = comment @time, @date = parse(date_time) @options = end |
Instance Method Details
#guess? ⇒ Boolean
48 49 50 51 52 53 |
# File 'lib/cease/eviction/command/date_time.rb', line 48 def guess? return true unless parsed_date !!parsed_date rescue true end |
#parsed_in_timezone ⇒ TZ::DateTimeWithOffset?
34 35 36 37 |
# File 'lib/cease/eviction/command/date_time.rb', line 34 def parsed_in_timezone return unless valid? tz.local_datetime(*local_datetime_args) end |
#tz ⇒ Object
55 56 57 58 59 60 |
# File 'lib/cease/eviction/command/date_time.rb', line 55 def tz ::TZInfo::Timezone.get( TIMEZONE_NAME_MAPPING[timezone_name] || TIMEZONE_NAME_MAPPING[DEFAULT_TIMEZONE] ) end |
#valid? ⇒ Boolean
39 40 41 42 43 44 45 46 |
# File 'lib/cease/eviction/command/date_time.rb', line 39 def valid? return false unless valid_time? return false if date && !valid_date? return false if timezone_name && !valid_timezone? true rescue false end |