Module: Dsu::Support::TimeFormatable
- Included in:
- CLI, Models::EntryGroup, Dsu::Services::EntryGroup::BrowseService, Dsu::Services::EntryGroup::EditorService, Dsu::Subcommands::Browse, Dsu::Subcommands::Delete, Dsu::Subcommands::Export, Dsu::Subcommands::Import, Dsu::Subcommands::List, Views::EntryGroup::Shared::NoEntriesToDisplay, Views::EntryGroup::Show
- Defined in:
- lib/dsu/support/time_formatable.rb
Overview
This module provides functions for formatting Time objects to display in the console.
Class Method Summary collapse
- .dd_mm_yyyy(time:, separator: '/') ⇒ Object
-
.formatted_time(time:) ⇒ Object
TODO: I18n.
-
.mm_dd(time:, separator: '/') ⇒ Object
TODO: I18n.
-
.mm_dd_yyyy(time:, separator: '/') ⇒ Object
TODO: I18n.
- .timezone_for(time:) ⇒ Object
-
.yyyy_mm_dd(time:, separator: '-') ⇒ Object
TODO: I18n.
-
.yyyy_mm_dd_or_through_for(times:) ⇒ Object
TODO: I18n.
Class Method Details
.dd_mm_yyyy(time:, separator: '/') ⇒ Object
42 43 44 |
# File 'lib/dsu/support/time_formatable.rb', line 42 def dd_mm_yyyy(time:, separator: '/') time.strftime("%d#{separator}%m#{separator}%Y") end |
.formatted_time(time:) ⇒ Object
TODO: I18n.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dsu/support/time_formatable.rb', line 14 def formatted_time(time:) time = time.in_time_zone today_yesterday_or_tomorrow = if time.today? 'Today' elsif time.yesterday? 'Yesterday' elsif time.tomorrow? 'Tomorrow' end time_zone = timezone_for(time: time) return time.strftime("%A, %Y-%m-%d #{time_zone}") unless today_yesterday_or_tomorrow time.strftime("%A, (#{today_yesterday_or_tomorrow}) %Y-%m-%d #{time_zone}") end |
.mm_dd(time:, separator: '/') ⇒ Object
TODO: I18n.
33 34 35 |
# File 'lib/dsu/support/time_formatable.rb', line 33 def mm_dd(time:, separator: '/') time.strftime("%m#{separator}%d") end |
.mm_dd_yyyy(time:, separator: '/') ⇒ Object
TODO: I18n.
38 39 40 |
# File 'lib/dsu/support/time_formatable.rb', line 38 def mm_dd_yyyy(time:, separator: '/') time.strftime("%m#{separator}%d#{separator}%Y") end |
.timezone_for(time:) ⇒ Object
46 47 48 |
# File 'lib/dsu/support/time_formatable.rb', line 46 def timezone_for(time:) time.zone end |
.yyyy_mm_dd(time:, separator: '-') ⇒ Object
TODO: I18n.
60 61 62 |
# File 'lib/dsu/support/time_formatable.rb', line 60 def yyyy_mm_dd(time:, separator: '-') time.strftime("%Y#{separator}%m#{separator}%d") end |
.yyyy_mm_dd_or_through_for(times:) ⇒ Object
TODO: I18n.
51 52 53 54 55 56 57 |
# File 'lib/dsu/support/time_formatable.rb', line 51 def yyyy_mm_dd_or_through_for(times:) return yyyy_mm_dd(time: times[0]) if times.one? times = [yyyy_mm_dd(time: times.min), yyyy_mm_dd(time: times.max)] I18n.t('information.dates.through', from: times[0], to: times[1]) end |