Class: Formatter::Date
- Inherits:
-
Object
- Object
- Formatter::Date
- Defined in:
- lib/formatter/date.rb,
lib/formatter/date/version.rb
Overview
Date formatter with time zone support.
Defined Under Namespace
Classes: TimeOrDateTime
Constant Summary collapse
- VERSION =
Gem version
'0.1.0'
Instance Method Summary collapse
-
#format(time_or_datetime) ⇒ String
Format Time or DateTime with formatter.
-
#identifier ⇒ String
Configured time zone identifier.
-
#initialize(time_zone, format = :iso8601, fraction = 0) ⇒ undefined
constructor
Initialize a formatter with the desired options.
-
#offset ⇒ Rational
Configured time zone offset.
Constructor Details
#initialize(time_zone, format = :iso8601, fraction = 0) ⇒ undefined
Initialize a formatter with the desired options.
:time_zone specifies which time zone to use when formatting.
:format specifies which format to use, it can either be a symbol of a predefined format or a string with a custom format which will be delegated to DateTime#strftime.
:fraction is length of fractional seconds to be used with predefined formats.
44 45 46 47 |
# File 'lib/formatter/date.rb', line 44 def initialize(time_zone, format = :iso8601, fraction = 0) self.time_zone = time_zone @formatter = formatter_for format, fraction end |
Instance Method Details
#format(time_or_datetime) ⇒ String
Format Time or DateTime with formatter
56 57 58 |
# File 'lib/formatter/date.rb', line 56 def format(time_or_datetime) formatter.call with_offset(time_or_datetime) end |
#identifier ⇒ String
Configured time zone identifier
65 66 67 |
# File 'lib/formatter/date.rb', line 65 def identifier time_zone.identifier end |
#offset ⇒ Rational
Configured time zone offset
74 75 76 |
# File 'lib/formatter/date.rb', line 74 def offset time_zone.current_period.utc_total_offset_rational end |