summaryrefslogtreecommitdiff
path: root/helpers/calendar_helpers.rb
blob: ed8ab1633e5f717032f984de71b29fa24012d483 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'date'

module CalendarHelpers

  FORMATS = {
    time_only: "%H:%M",
    date_only: "%a. %d.%m",
    date_string_short: "%e. %b %Y",
    log: "%Y-%m-%d %H:%M"
  }

  class Event

    # TODO i18n weekdays, group dates

    def initialize(args={})
      @summary    = args.fetch("summary")
      @start_time = DateTime.parse(args.fetch("start"))
      @end_time   = DateTime.parse(args.fetch("end"))
    end

    def summary
      @summary
    end

    def start_time
      @start_time.strftime(FORMATS[:time_only])
    end

    def end_time
      @end_time.strftime(FORMATS[:time_only])
    end

    def date
      @start_time.strftime(FORMATS[:date_only])
    end

  end


end