denny/ShinyCMS-ruby

View on GitHub
plugins/ShinyCMS/app/helpers/shinycms/dates_helper.rb

Summary

Maintainability
A
45 mins
Test Coverage
F
56%
# frozen_string_literal: true

# ShinyCMS ~ https://shinycms.org
#
# Copyright 2009-2024 Denny de la Haye ~ https://denny.me
#
# ShinyCMS is free software; you can redistribute it and/or modify it under the terms of the GPL (version 2 or later)

module ShinyCMS
  # Useful methods for displaying/saving dates and times
  module DatesHelper
    def display_date_at_time( timestamp )
      return unless timestamp.is_a? Time

      date = timestamp.localtime.to_s :shinydate_with_day
      time = timestamp.localtime.to_s :time

      I18n.t( 'shinycms.shiny_date_helper.date_at_time', time: time, date: date )
    end

    def display_time_on_date( timestamp )
      return unless timestamp.is_a? Time

      date = timestamp.localtime.to_s :shinydate_with_day
      time = timestamp.localtime.to_s :time

      I18n.t( 'shinycms.shiny_date_helper.time_on_date', time: time, date: date )
    end

    def display_time_on_date_no_day( timestamp )
      return unless timestamp.is_a? Time

      date = timestamp.localtime.to_s :shinydate
      time = timestamp.localtime.to_s :time

      I18n.t( 'shinycms.shiny_date_helper.time_on_date', time: time, date: date )
    end

    def display_date( timestamp )
      return unless timestamp.is_a? Time

      timestamp.localtime.to_s :shinydate_with_day
    end

    def display_time( timestamp )
      return unless timestamp.is_a? Time

      timestamp.localtime.to_s :time
    end
  end
end