Sha256: 7bf3ef2825a624fdef112c78235abeaadb57c2b2480464cabac3ed2e5130e3a9

Contents?: true

Size: 1.2 KB

Versions: 42

Compression:

Stored size: 1.2 KB

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

module TwitterCldr
  module Localized

    class LocalizedDate < LocalizedDateTime
      def to_datetime(time = Time.now)
        dt = DateTime.parse("#{@base_obj.strftime("%Y-%m-%d")}T#{unwrap_time_obj(time).strftime("%H:%M:%S%z")}")
        LocalizedDateTime.new(dt, @locale, chain_params)
      end

      def to_time(base = Time.now)
        case @base_obj
          when Time
            LocalizedTime.new(@base_obj, @locale, chain_params)
          when Date, DateTime
            LocalizedTime.new(@base_obj.to_time, @locale, chain_params)
          else
            nil
        end
      end

      protected

      def unwrap_time_obj(time)
        time.is_a?(LocalizedTime) ? time.base_obj : time
      end

      def base_in_timezone
        time = unwrap_time_obj(to_time)
        timezone_info.utc_to_local(time.is_a?(DateTime) ? time.new_offset(0) : time.utc)
      end

      def data_reader_for(type, options = {})
        TwitterCldr::DataReaders::DateDataReader.new(
          locale, options.merge({
            calendar_type: calendar_type,
            type: type
          })
        )
      end

    end
  end
end

Version data entries

42 entries across 42 versions & 2 rubygems

Version Path
twitter_cldr-6.13.0 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.12.1 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.12.0 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.11.5 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.11.4 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.11.3 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.11.2 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.11.1 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.11.0 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.10.0 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.9.0 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.8.0 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.7.0 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.6.2 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.6.1 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.6.0 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.5.0 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.4.0 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.3.0 lib/twitter_cldr/localized/localized_date.rb
twitter_cldr-6.2.0 lib/twitter_cldr/localized/localized_date.rb