Module: OpenEHR::AssumedLibraryTypes::TimeDefinitions
- Included in:
- ISO8601DateModule, ISO8601DurationModule, ISO8601TimeModule
- Defined in:
- lib/open_ehr/assumed_library_types.rb
Overview
< Any
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
- .valid_day?(y, m, d) ⇒ Boolean
- .valid_hour?(h, m = nil, s = nil) ⇒ Boolean
- .valid_minute?(mi) ⇒ Boolean
- .valid_month?(mo) ⇒ Boolean
- .valid_second?(s) ⇒ Boolean
- .valid_year?(year) ⇒ Boolean
Class Method Details
.valid_day?(y, m, d) ⇒ Boolean
150 151 152 153 154 155 156 157 158 |
# File 'lib/open_ehr/assumed_library_types.rb', line 150 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
160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/open_ehr/assumed_library_types.rb', line 160 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
173 174 175 |
# File 'lib/open_ehr/assumed_library_types.rb', line 173 def self.valid_minute?(mi) mi >= 0 and mi < MINUTES_IN_HOUR end |
.valid_month?(mo) ⇒ Boolean
181 182 183 |
# File 'lib/open_ehr/assumed_library_types.rb', line 181 def self.valid_month?(mo) mo >= 1 and mo <= MONTH_IN_YEAR end |
.valid_second?(s) ⇒ Boolean
177 178 179 |
# File 'lib/open_ehr/assumed_library_types.rb', line 177 def self.valid_second?(s) s >= 0 and s < SECONDS_IN_MINUTE end |
.valid_year?(year) ⇒ Boolean
146 147 148 |
# File 'lib/open_ehr/assumed_library_types.rb', line 146 def self.valid_year?(year) return !year.nil? && year >= 0 end |