Module: PartialDate
- Defined in:
- lib/partial-date/date.rb,
lib/partial-date/error.rb,
lib/partial-date/version.rb
Overview
Public module containing Date, Error and Version types.
Defined Under Namespace
Classes: Date, DayError, MonthError, PartialDateError, YearError
Constant Summary collapse
- DAY_MASK =
Key:
The first 5 bits are the day (max 31) The next 4 bits are the month (max 12) The next 20 bits are the year (max 1048576) The most significant bit (MSB) is a 1 bit sign bit (for negative years). 0b000000000000000000000000011111
- MONTH_MASK =
0b000000000000000000000111100000
- YEAR_MASK =
0b011111111111111111111000000000
- SIGN_MASK =
0b100000000000000000000000000000
- ZERO_SIGN_MASK =
0b011111111111111111111111111111
- ZERO_YEAR_MASK =
0b100000000000000000000111111111
- ZERO_MONTH_MASK =
0b111111111111111111111000011111
- ZERO_DAY_MASK =
0b111111111111111111111111100000
- SIGN_SHIFT =
29- YEAR_SHIFT =
9- MONTH_SHIFT =
5- REMOVALS =
/[\/\,\-\s]/- FORMATS =
TODO: Implement i18n support detecting whether a load path has been set or not and if not - setting it here to a default set of translations that match the generally available tranlsations for localizing dates.
github.com/svenfuchs/i18n/blob/master/lib/i18n/backend/base.rb format = format.to_s.gsub(/%/) do |match|
case match when '%a' then I18n.t(:"date.abbr_day_names", :locale => locale, :format => format)[object.wday] when '%A' then I18n.t(:"date.day_names", :locale => locale, :format => format)[object.wday] when '%b' then I18n.t(:"date.abbr_month_names", :locale => locale, :format => format)[object.mon] when '%B' then I18n.t(:"date.month_names", :locale => locale, :format => format)[object.mon] when '%p' then I18n.t(:"time.#{object.hour < 12 ? :am : :pm}", :locale => locale, :format => format) if object.respond_to? :hour endend
{ :default => "%Y-%m-%d", :short => "%d %m %Y", :medium => "%d %b %Y", :long => "%d %B %Y", :number => "%Y%m%d" }
- FORMAT_METHODS =
{ "%Y" => lambda { |d| (d.year != 0) ? d.year.to_s.rjust(4, '0') : ""}, "%m" => lambda { |d| (d.month != 0) ? d.month.to_s.rjust(2, '0') : "" }, "%b" => lambda { |d| (d.month != 0) ? ABBR_MONTH_NAMES[d.month - 1] : "" }, "%B" => lambda { |d| (d.month != 0) ? MONTH_NAMES[d.month - 1] : "" }, "%d" => lambda { |d| (d.day != 0) ? d.day.to_s.rjust(2, '0') : "" }, "%e" => lambda { |d| (d.day != 0) ? d.day.to_s : "" } }
- MONTH_NAMES =
%w[January, February, March, April, May, June, July, August, September, October, November, December,]- ABBR_MONTH_NAMES =
%w[Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec,]- VERSION =
partial-date version
"1.2.3"