Module: Sequel::Postgres::ExtendedDateSupport
- Defined in:
- lib/sequel/extensions/pg_extended_date_support.rb
Defined Under Namespace
Modules: DatasetMethods
Constant Summary collapse
- DATE_YEAR_1 =
Date.new(1)
- DATETIME_YEAR_1 =
DateTime.new(1)
- TIME_YEAR_1 =
Time.at(-62135596800).utc
- INFINITE_TIMESTAMP_STRINGS =
['infinity'.freeze, '-infinity'.freeze].freeze
- INFINITE_DATETIME_VALUES =
([PLUS_INFINITY, MINUS_INFINITY] + INFINITE_TIMESTAMP_STRINGS).freeze
- PLUS_DATE_INFINITY =
Date::Infinity.new
- MINUS_DATE_INFINITY =
-PLUS_DATE_INFINITY
Instance Attribute Summary collapse
-
#convert_infinite_timestamps ⇒ Object
Whether infinite timestamps/dates should be converted on retrieval.
Class Method Summary collapse
-
.extended(db) ⇒ Object
Add dataset methods and update the conversion proces for dates and timestamps.
Instance Method Summary collapse
-
#to_application_timestamp(value) ⇒ Object
Handle BC dates in timestamps by moving the BC from after the time to after the date, to appease ruby’s date parser.
Instance Attribute Details
#convert_infinite_timestamps ⇒ Object
Whether infinite timestamps/dates should be converted on retrieval. By default, no conversion is done, so an error is raised if you attempt to retrieve an infinite timestamp/date. You can set this to :nil to convert to nil, :string to leave as a string, or :float to convert to an infinite float.
45 46 47 |
# File 'lib/sequel/extensions/pg_extended_date_support.rb', line 45 def @convert_infinite_timestamps end |
Class Method Details
.extended(db) ⇒ Object
Add dataset methods and update the conversion proces for dates and timestamps.
34 35 36 37 38 39 |
# File 'lib/sequel/extensions/pg_extended_date_support.rb', line 34 def self.extended(db) db.extend_datasets(DatasetMethods) procs = db.conversion_procs procs[1082] = ::Sequel.method(:string_to_date) procs[1184] = procs[1114] = db.method(:to_application_timestamp) end |
Instance Method Details
#to_application_timestamp(value) ⇒ Object
Handle BC dates in timestamps by moving the BC from after the time to after the date, to appease ruby’s date parser. If convert_infinite_timestamps is true and the value is infinite, return an appropriate value based on the convert_infinite_timestamps setting.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/sequel/extensions/pg_extended_date_support.rb', line 85 def (value) if value.is_a?(String) && (m = value.match(/(?:(?:[-+]\d\d:\d\d)(:\d\d)?)?( BC)?\z/)) && (m[1] || m[2]) if m[2] value = value.sub(' BC', '').sub(' ', ' BC ') end if m[1] dt = DateTime.parse(value) dt = dt.to_time unless Sequel.datetime_class == DateTime Sequel.(dt, Sequel.application_timezone) else super(value) end elsif case value when *INFINITE_TIMESTAMP_STRINGS (value) else super end else super end end |