def to_era(format = "%o%E.%m.%d", era_names: ERA_NAME_DEFAULTS)
      raise EraJa::DateOutOfRangeError unless era_convertible?

      @era_format = format.gsub(/%J/, "%J%")
      str_time = strftime(@era_format)
      if @era_format =~ /%([EOo]|1O)/
        case
        when self.to_time < ::Time.mktime(1912,7,30)
          str_time = era_year(year - 1867, :meiji, era_names)
        when self.to_time < ::Time.mktime(1926,12,25)
          str_time = era_year(year - 1911, :taisho, era_names)
        when self.to_time < ::Time.mktime(1989,1,8)
          str_time = era_year(year - 1925, :showa, era_names)
        when self.to_time < ::Time.mktime(2019, 5, 1)
          str_time = era_year(year - 1988, :heisei, era_names)
        else
          str_time = era_year(year - 2018, :reiwa, era_names)
        end
      end
      str_time.gsub(/%J(\d+)/) { to_kanzi($1) }
    end
def to_era(format = "%o%E.%m.%d", era_names: ERA_NAME_DEFAULTS)
      raise EraJa::DateOutOfRangeError unless era_convertible?

      @era_format = format.gsub(/%J/, "%J%")
      str_time = strftime(@era_format)
      if @era_format =~ /%([EOo]|1O)/
        case
        when self.to_time < ::Time.mktime(1912,7,30)
          str_time = era_year(year - 1867, :meiji, era_names)
        when self.to_time < ::Time.mktime(1926,12,25)
          str_time = era_year(year - 1911, :taisho, era_names)
        when self.to_time < ::Time.mktime(1989,1,8)
          str_time = era_year(year - 1925, :showa, era_names)
        when self.to_time < ::Time.mktime(2019, 5, 1)
          str_time = era_year(year - 1988, :heisei, era_names)
        else
          str_time = era_year(year - 2018, :reiwa, era_names)
        end
      end
      str_time.gsub(/%J(\d+)/) { to_kanzi($1) }
    end
Convert to Japanese era.
 @param [String] format_string
   Time#strftime format string can be used
   #### extra format string
   * %o - era(alphabet)
   * %O - era(kanzi)
   * %E - era year
   * %J - kanzi number
 @param [Hash] era_names
    If you want to convert custom to era strings (eg `平`, `h`), you can set this argument.
    key is `:meiji' or `:taisho' or `:showa` or `:heisei` or `:reiwa`.
    value is ["alphabet era name"(ex `h`, `s`)(related to `%o`), "multibyte era name"(eg `平`, `昭`)(related to `%O`)].
    this argument is same as one element of ERA_NAME_DEFAULTS.
 @return [String]