Proposal: strftime-based calendar/datetime formatting

Ok, after a day of thinking, I believe I have a better understanding of the issues we are discussing. The trouble here is that we have four different concerns between the formatter and the calendar:

  • localization - default date, default time and default date time)
  • week_of_year - what is the initial day of the week (monday or sunday) and on which week the year starts (it is also part of localization)
  • translation so weekday 1 is monday (en) / segunda-feira (pt-br) and month 2 is february (en) / fevereiro (pt-br)
  • padding - which is how to pad each entry, which is calendar specific

The problem is that we are trying to fit those concerns into either the formatter or the calendar and having trouble doing so. Here is a new proposal: we get rid of the formatter and instead we pass multiple options. The options are:

  • default_date - configures the default date
  • default_time - configures the default time
  • default_datetime - configures the default datetime
  • week_of_year - a function that receives calendar, year, month, day and returns the week_of_year tuple
  • month_names - a function that converts integers to month names: fn 1 -> "January"; 2 -> "February"; ... end
  • abbreviated_month_names - a function that converts integers to abbreviated month names: fn 1 -> "Jan"; 2 => "Feb"; ... end
  • day_of_week_names - a function that converts integers to day of week names: fn 1 -> "Monday"; 2 -> ... end
  • abbreviated_day_of_week_names - a function that converts integers to day of week names: fn 1 -> "Monday"; 2 -> ... end
  • default_padding - (:zero, :space, :none)
  • year_padding - 4
  • month_padding - 2
  • day_padding - 2
  • hour_padding - 2
  • minute_padding - 2
  • second_padding - 2
  • day_of_week_padding - 2
  • day_of_year_padding - 2
  • week_of_year_padding - 2

The calendar should return a map with defaults for all of those options which can be customized when the format function is invoked.

AM/PM

For AM/PM, we will add a new function to Calendar that returns :am, :pm, :noon or :midnight. We need moon and midnight because some languages consider those different parts of am/pm. Therefore we will also add an option to the formatter like this:

  • am_pm - a function that converts parts am/pm info: fn :am -> "am"; :midnight -> "am"; :pm -> "pm"; :noon -> "pm" end
2 Likes