Class: OpenEHR::AssumedLibraryTypes::TimeDefinitions
- Inherits:
-
Any
- Object
- Any
- OpenEHR::AssumedLibraryTypes::TimeDefinitions
show all
- Defined in:
- lib/open_ehr/assumed_library_types.rb
Overview
Constant Summary
collapse
- DAYS_IN_LEAP_YEAR =
366
- DAYS_IN_WEEK =
7
- DAYS_IN_YEAR =
365
- HOURS_IN_DAY =
24
- MAX_DAYS_IN_MONTH =
31
- MAX_DAYS_IN_YEAR =
366
- MINUTES_IN_HOUR =
60
- MONTH_IN_YEAR =
12
- NOMINAL_DAYS_IN_MONTH =
30.42
- NOMINAL_DAYS_IN_YEAR =
365.24
- SECONDS_IN_MINUTE =
60
Class Method Summary
collapse
Class Method Details
.valid_day?(y, m, d) ⇒ Boolean
100
101
102
103
104
105
106
107
108
|
# File 'lib/open_ehr/assumed_library_types.rb', line 100
def self.valid_day?(y, m, d)
unless y.nil? || m.nil? || d.nil?
return Date.valid_date?(y,m,d)
end
if (y.nil?) || (m.nil? && !d.nil?)
return false
end
return self.valid_year?(y) && self.valid_month?(m)
end
|
.valid_hour?(h, m = nil, s = nil) ⇒ Boolean
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/open_ehr/assumed_library_types.rb', line 110
def self.valid_hour?(h,m = nil, s = nil)
if h.nil?
return false
end
if !m.nil? and !valid_minute?(m)
return false
end
if !s.nil? and (!m.nil? and !valid_second?(s))
return false
end
(h >= 0 and h < HOURS_IN_DAY) or (h == HOURS_IN_DAY and m == 0 and s == 0)
end
|
.valid_minute?(mi) ⇒ Boolean
123
124
125
|
# File 'lib/open_ehr/assumed_library_types.rb', line 123
def self.valid_minute?(mi)
mi >= 0 and mi < MINUTES_IN_HOUR
end
|
.valid_month?(mo) ⇒ Boolean
131
132
133
|
# File 'lib/open_ehr/assumed_library_types.rb', line 131
def self.valid_month?(mo)
mo >= 1 and mo <= MONTH_IN_YEAR
end
|
.valid_second?(s) ⇒ Boolean
127
128
129
|
# File 'lib/open_ehr/assumed_library_types.rb', line 127
def self.valid_second?(s)
s >= 0 and s < SECONDS_IN_MINUTE
end
|
.valid_year?(year) ⇒ Boolean
96
97
98
|
# File 'lib/open_ehr/assumed_library_types.rb', line 96
def self.valid_year?(year)
return !year.nil? && year >= 0
end
|