Class: Time

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

Overview

Utility time methods

Instance Method Summary collapse

Instance Method Details

#format_start_dateObject

Converts start_date from date to formatted string



36
37
38
39
40
41
42
# File 'lib/gsr.rb', line 36

def format_start_date()
	if Date.valid_date?(self.year, self.month, self.day)
		return self.month.to_s + '/' + self.day.to_s
	else
		raise "Invalid start date specified."
	end
end

#format_start_timeObject

Converts start_time from time to formatted string



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
# File 'lib/gsr.rb', line 7

def format_start_time()
	#Hour logic
	if self.hour < 0
		raise "Invalid self specified: hour can't be negative"
	elsif self.hour == 0
		hour = 12
		half = "AM"
	elsif self.hour == 12
		hour = 12
		half = "PM"
	elsif self.hour > 12
		hour = self.hour - 12
		half = "PM"
	else # 0 < self.hour < 12
		hour = self.hour
		half = "AM"
	end
	
	#Minute logic
	if self.min < 10
		min = "0" + self.min.to_s
	else
		min = self.min.to_s
	end
	
	return hour.to_s + ':' + min + " " + half
end