Module: Spree::Helpers::LocalTimeHelper

Defined in:
app/controllers/spree/helpers/local_time_helper.rb

Defined Under Namespace

Modules: LocalTime

Instance Method Summary collapse

Instance Method Details

#local_date(time, options = nil) ⇒ Object



21
22
23
24
25
# File 'app/controllers/spree/helpers/local_time_helper.rb', line 21

def local_date(time, options = nil)
  options, format = extract_options_and_value(options, :format)
  options[:format] = format || LocalTime.default_date_format
  local_time time, options
end

#local_relative_time(time, options = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'app/controllers/spree/helpers/local_time_helper.rb', line 27

def local_relative_time(time, options = nil)
  time = utc_time(time)
  options, type = extract_options_and_value(options, :type)

  options[:data] ||= {}
  options[:data].merge! local: type

  time_tag time, time.strftime(LocalTime.default_time_format), options
end

#local_time(time, options = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/spree/helpers/local_time_helper.rb', line 9

def local_time(time, options = nil)
  time = utc_time(time)

  options, format = extract_options_and_value(options, :format)
  format = find_time_format(format)

  options[:data] ||= {}
  options[:data].merge! local: :time, format: format

  time_tag time, time.strftime(format), options
end

#local_time_ago(time, options = nil) ⇒ Object



37
38
39
40
41
# File 'app/controllers/spree/helpers/local_time_helper.rb', line 37

def local_time_ago(time, options = nil)
  options, * = extract_options_and_value(options, :type)
  options[:type] = 'time-ago'
  local_relative_time time, options
end

#utc_time(time_or_date) ⇒ Object



43
44
45
46
47
48
49
# File 'app/controllers/spree/helpers/local_time_helper.rb', line 43

def utc_time(time_or_date)
  if time_or_date.respond_to?(:in_time_zone)
    time_or_date.in_time_zone.utc
  else
    time_or_date.to_time.utc
  end
end