Class: Downtime::Timestamp

Inherits:
Object
  • Object
show all
Defined in:
lib/downtime/timestamp.rb

Constant Summary collapse

@@time_pattern =
"%Y-%m-%d-%H-%M"
@@time_pattern_zone =
"%Y-%m-%d-%H-%M %Z"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time = DateTime.now) ⇒ Timestamp

Returns a new instance of Timestamp.



13
14
15
# File 'lib/downtime/timestamp.rb', line 13

def initialize time=DateTime.now
  @datetime = time
end

Instance Attribute Details

#datetimeObject

Returns the value of attribute datetime.



7
8
9
# File 'lib/downtime/timestamp.rb', line 7

def datetime
  @datetime
end

Class Method Details

.from_s(string) ⇒ Object

Will create CET times.



22
23
24
# File 'lib/downtime/timestamp.rb', line 22

def self.from_s string
  Timestamp.new(DateTime.strptime string + " CET", @@time_pattern_zone)
end

.time_patternObject



9
10
11
# File 'lib/downtime/timestamp.rb', line 9

def self.time_pattern
  @@time_pattern
end

Instance Method Details

#-(other_timestamp) ⇒ Object

Returns difference to other timestamp in minutes.



27
28
29
# File 'lib/downtime/timestamp.rb', line 27

def -(other_timestamp)
  ((@datetime.to_time - other_timestamp.datetime.to_time) / 60.0).to_i
end

#to_sObject



17
18
19
# File 'lib/downtime/timestamp.rb', line 17

def to_s
  @datetime.strftime @@time_pattern
end