module JapaneseCalendar::Weekday

Weekday extensions to Date, DateTime and Time.

Public Instance Methods

strftime(format) click to toggle source

Formats the day of the week according to the directives in the given format string.

Format directives:

%JA - The full weekday name in Japanese ("日曜日")
%Ja - The abbreviated weekday name in Japanese ("日")

Examples:

date_of_birth = Time.new(1978, 7, 19)

date_of_birth.strftime("%JA")  # => "水曜日"
date_of_birth.strftime("%Ja")  # => "水"

date_of_birth.strftime("%-Y年%-m月%-d日(%Ja)") # => "1978年7月19日(水)"
Calls superclass method
# File lib/japanese_calendar/weekday.rb, line 26
def strftime(format)
  string = super(format)
  string.gsub(weekday_pattern, weekday_conversion)
end

Private Instance Methods

weekday_conversion() click to toggle source

Returns a hash representing the format directives of the day of the week.

# File lib/japanese_calendar/weekday.rb, line 34
def weekday_conversion
  {
    '%JA' => weekday_name,
    '%Ja' => weekday_abbreviation
  }
end
weekday_pattern() click to toggle source

Returns a Regexp object representing the format directives of the day of the week (/%JA|%Ja/).

# File lib/japanese_calendar/weekday.rb, line 43
def weekday_pattern
  Regexp.union(weekday_conversion.keys)
end