Class: Cldr::Format::Date

Inherits:
Cldr::Format::Datetime::Base show all
Defined in:
lib/cldr/format/date.rb

Constant Summary collapse

PATTERN =
/G{1,5}|y+|Y+|Q{1,4}|q{1,5}|M{1,5}|L{1,5}|d{1,2}|F{1}|E{1,5}|e{1,5}|c{1,5}/
METHODS =

ignoring u, l, g, j, A

{ # ignoring u, l, g, j, A
  'G' => :era,
  'y' => :year,
  'Y' => :year_of_week_of_year,
  'Q' => :quarter,
  'q' => :quarter_stand_alone,
  'M' => :month,
  'L' => :month_stand_alone,
  'w' => :week_of_year,
  'W' => :week_of_month,
  'd' => :day,
  'D' => :day_of_month,
  'F' => :day_of_week_in_month,
  'E' => :weekday,
  'e' => :weekday_local,
  'c' => :weekday_local_stand_alone,
}
WEEKDAY_KEYS =
[:sun, :mon, :tue, :wed, :thu, :fri, :sat]

Instance Attribute Summary

Attributes inherited from Cldr::Format::Datetime::Base

#calendar

Instance Method Summary collapse

Methods inherited from Cldr::Format::Datetime::Base

#initialize

Constructor Details

This class inherits a constructor from Cldr::Format::Datetime::Base

Instance Method Details

#day(date, pattern, length) ⇒ Object



111
112
113
114
115
116
117
118
# File 'lib/cldr/format/date.rb', line 111

def day(date, pattern, length)
  case length
  when 1
    date.day.to_s
  when 2
    date.day.to_s.rjust(length, '0')
  end
end

#day_of_week_in_month(date, pattern, length) ⇒ Object

e.g. 2nd Wed in July



38
39
40
# File 'lib/cldr/format/date.rb', line 38

def day_of_week_in_month(date, pattern, length) # e.g. 2nd Wed in July
  raise 'not implemented'
end

#era(date, pattern, length) ⇒ Object



23
24
25
# File 'lib/cldr/format/date.rb', line 23

def era(date, pattern, length)
  raise 'not implemented'
end

#month(date, pattern, length) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/cldr/format/date.rb', line 74

def month(date, pattern, length)
  case length
  when 1
    date.month.to_s
  when 2
    date.month.to_s.rjust(length, '0')
  when 3
    calendar[:months][:format][:abbreviated][date.month]
  when 4
    calendar[:months][:format][:wide][date.month]
  when 5
    raise 'not yet implemented (requires cldr\'s "multiple inheritance")'
    calendar[:months][:format][:narrow][date.month]
  else
    # raise unknown date format
  end
end

#month_stand_alone(date, pattern, length) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/cldr/format/date.rb', line 92

def month_stand_alone(date, pattern, length)
  case length
  when 1
    date.month.to_s
  when 2
    date.month.to_s.rjust(length, '0')
  when 3
    raise 'not yet implemented (requires cldr\'s "multiple inheritance")'
    calendar[:months][:'stand-alone'][:abbreviated][date.month]
  when 4
    raise 'not yet implemented (requires cldr\'s "multiple inheritance")'
    calendar[:months][:'stand-alone'][:wide][date.month]
  when 5
    calendar[:months][:'stand-alone'][:narrow][date.month]
  else
    # raise unknown date format
  end
end

#quarter(date, pattern, length) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cldr/format/date.rb', line 42

def quarter(date, pattern, length)
  quarter = (date.month.to_i - 1) / 3 + 1
  case length
  when 1
    quarter.to_s
  when 2
    quarter.to_s.rjust(length, '0')
  when 3
    calendar[:quarters][:format][:abbreviated][quarter]
  when 4
    calendar[:quarters][:format][:wide][quarter]
  end
end

#quarter_stand_alone(date, pattern, length) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/cldr/format/date.rb', line 56

def quarter_stand_alone(date, pattern, length)
  quarter = (date.month.to_i - 1) / 3 + 1
  case length
  when 1
    quarter.to_s
  when 2
    quarter.to_s.rjust(length, '0')
  when 3
    raise 'not yet implemented (requires cldr\'s "multiple inheritance")'
    # calendar[:quarters][:'stand-alone'][:abbreviated][key]
  when 4
    raise 'not yet implemented (requires cldr\'s "multiple inheritance")'
    # calendar[:quarters][:'stand-alone'][:wide][key]
  when 5
    calendar[:quarters][:'stand-alone'][:narrow][quarter]
  end
end

#weekday(date, pattern, length) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
# File 'lib/cldr/format/date.rb', line 122

def weekday(date, pattern, length)
  key = WEEKDAY_KEYS[date.wday]
  case length
  when 1..3
    calendar[:days][:format][:abbreviated][key]
  when 4
    calendar[:days][:format][:wide][key]
  when 5
    calendar[:days][:'stand-alone'][:narrow][key]
  end
end

#weekday_local(date, pattern, length) ⇒ Object



134
135
136
137
# File 'lib/cldr/format/date.rb', line 134

def weekday_local(date, pattern, length)
  # "Like E except adds a numeric value depending on the local starting day of the week"
  raise 'not implemented (need to defer a country to lookup the local first day of week from weekdata)'
end

#weekday_local_stand_alone(date, pattern, length) ⇒ Object



139
140
141
# File 'lib/cldr/format/date.rb', line 139

def weekday_local_stand_alone(date, pattern, length)
  raise 'not implemented (need to defer a country to lookup the local first day of week from weekdata)'
end

#year(date, pattern, length) ⇒ Object



27
28
29
30
31
32
# File 'lib/cldr/format/date.rb', line 27

def year(date, pattern, length)
  year = date.year.to_s
  year = year.length == 1 ? year : year[-2, 2] if length == 2
  year = year.rjust(length, '0') if length > 1
  year
end

#year_of_week_of_year(date, pattern, length) ⇒ Object



34
35
36
# File 'lib/cldr/format/date.rb', line 34

def year_of_week_of_year(date, pattern, length)
  raise 'not implemented'
end