Home>

I am creating a memo app using Simple calendar, so I want to change the date display (only for month and day)

The problem i am having

Currently it is displayed as 2020-01-01image

.simple-calendar
  .calendar-heading {style:'text-align: center;'}
    = link_to t ('simple_calendar.previous', default:'<<'), calendar.url_for_previous_view
    % span.calendar-title
      = t ('date.month_names') [start_date.month]
      = start_date.year
    = link_to t ('simple_calendar.next', default:'>>'), calendar.url_for_next_view
  % table.table.table-striped
    % header
      % tr
        --date_range.slice (0, 7) .each do | day |
          % th = t ('date.abbr_day_names') [day.wday]
    % tbody
      --date_range.each_slice (7) do | week |
        % tr
          --week.each do | day |
            = content_tag: td, class: calendar.td_classes_for (day) do
              --if defined? (Haml)&&respond_to? (: Block_is_haml?)&&block_is_haml? (Passed_block)
                --capture_haml (day, sorted_events.fetch (day, []),&passed_block)
              --other
                --passed_block.call day, sorted_events.fetch (day, [])
  • Answer # 1

    It was solved by adding .strftime ("% m /% d") to the day below.

    .simple-calendar
      .calendar-heading {style:'text-align: center;'}
        = link_to t ('simple_calendar.previous', default:'<<'), calendar.url_for_previous_view
        % span.calendar-title
          = t ('date.month_names') [start_date.month]
          = start_date.year
        = link_to t ('simple_calendar.next', default:'>>'), calendar.url_for_next_view
      % table.table.table-striped
        % header
          % tr
            --date_range.slice (0, 7) .each do | day |
              % th = t ('date.abbr_day_names') [day.wday]
        % tbody
          --date_range.each_slice (7) do | week |
            % tr
              --week.each do | day |
                = content_tag: td, class: calendar.td_classes_for (day) do
                  --if defined? (Haml)&&respond_to? (: Block_is_haml?)&&block_is_haml? (Passed_block)
                    --capture_haml (day.strftime ("% m /% d"), sorted_events.fetch (day, []),&passed_block)
                  --other
                    --passed_block.call day.strftime ("% m /% d"), sorted_events.fetch (day, [])

Related articles