Sha256: f496dc9dc48cd82261dda08e0583743232d7634cb77029019295a2b560fb0e50

Contents?: true

Size: 1.1 KB

Versions: 21

Compression:

Stored size: 1.1 KB

Contents

# -*- ruby -*-

require 'date'
require 'json'

module PG
	module TextDecoder
		class Date < SimpleDecoder
			ISO_DATE = /\A(\d{4})-(\d\d)-(\d\d)\z/

			def decode(string, tuple=nil, field=nil)
				if string =~ ISO_DATE
					::Date.new $1.to_i, $2.to_i, $3.to_i
				else
					string
				end
			end
		end

		class JSON < SimpleDecoder
			def decode(string, tuple=nil, field=nil)
				::JSON.parse(string, quirks_mode: true)
			end
		end

		# Convenience classes for timezone options
		class TimestampUtc < Timestamp
			def initialize(params={})
				super(params.merge(flags: PG::Coder::TIMESTAMP_DB_UTC | PG::Coder::TIMESTAMP_APP_UTC))
			end
		end
		class TimestampUtcToLocal < Timestamp
			def initialize(params={})
				super(params.merge(flags: PG::Coder::TIMESTAMP_DB_UTC | PG::Coder::TIMESTAMP_APP_LOCAL))
			end
		end
		class TimestampLocal < Timestamp
			def initialize(params={})
				super(params.merge(flags: PG::Coder::TIMESTAMP_DB_LOCAL | PG::Coder::TIMESTAMP_APP_LOCAL))
			end
		end

		# For backward compatibility:
		TimestampWithoutTimeZone = TimestampLocal
		TimestampWithTimeZone = Timestamp
	end
end # module PG

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
pg-1.1.4-x86-mingw32 lib/pg/text_decoder.rb
pg-1.1.4-x64-mingw32 lib/pg/text_decoder.rb
pg-1.1.4 lib/pg/text_decoder.rb
pg-1.1.3-x86-mingw32 lib/pg/text_decoder.rb
pg-1.1.3-x64-mingw32 lib/pg/text_decoder.rb
pg-1.1.3 lib/pg/text_decoder.rb
pg-1.1.2-x86-mingw32 lib/pg/text_decoder.rb
pg-1.1.2-x64-mingw32 lib/pg/text_decoder.rb
pg-1.1.2 lib/pg/text_decoder.rb
pg-1.1.1-x86-mingw32 lib/pg/text_decoder.rb
pg-1.1.1-x64-mingw32 lib/pg/text_decoder.rb
pg-1.1.1 lib/pg/text_decoder.rb
pg-1.1.0-x86-mingw32 lib/pg/text_decoder.rb
pg-1.1.0-x64-mingw32 lib/pg/text_decoder.rb
pg-1.1.0 lib/pg/text_decoder.rb
pg-1.1.0.pre20180730171000-x86-mingw32 lib/pg/text_decoder.rb
pg-1.1.0.pre20180730171000-x64-mingw32 lib/pg/text_decoder.rb
pg-1.1.0.pre20180730171000 lib/pg/text_decoder.rb
pg-1.1.0.pre20180730144600-x86-mingw32 lib/pg/text_decoder.rb
pg-1.1.0.pre20180730144600-x64-mingw32 lib/pg/text_decoder.rb