Module: ZTK::GoogleChart::Base::Dates

Included in:
ZTK::GoogleChart::Base
Defined in:
lib/ztk/google_chart/base/dates.rb

Constant Summary

DATE_HELPERS =
{
  :second => -1,
  :minute => -2,
  :hour => -3,
  :day => -4,
  :month => -5,
  :year => -6
}

Instance Method Summary (collapse)

Instance Method Details

- (Object) date_format(*args)



61
62
63
# File 'lib/ztk/google_chart/base/dates.rb', line 61

def date_format(*args)
  %w( %Y %%d %-d %-H %-M %-S )[*args].join(',')
end

- (Object) date_scale(scale, *args)



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ztk/google_chart/base/dates.rb', line 16

def date_scale(scale, *args)
  case scale
  when :year then
    send(:date_month, *args)
  when :month, :week then
    send(:date_day, *args)
  when :day then
    send(:date_hour, *args)
  when :hour then
    send(:date_minute, *args)
  when :minute then
    send(:date_second, *args)
  end
end

- (Object) date_seed(start_time, end_time, unit, default)



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ztk/google_chart/base/dates.rb', line 31

def date_seed(start_time, end_time, unit, default)
  start_time = start_time.dup
  timeline = Hash.new

  scale = case unit
  when :year then
    :month
  when :month, :week then
    :day
  when :day then
    :hour
  when :hour then
    :minute
  when :minute then
    :second
  end

  loop do
    timeline.merge!(date_scale(unit, start_time) => default.dup)
    start_time += 1.send(scale)
    break if (start_time > end_time)
  end

  timeline
end

- (Object) date_wrapper(value)



57
58
59
# File 'lib/ztk/google_chart/base/dates.rb', line 57

def date_wrapper(value)
  "new Date(#{value})"
end