Module: OpenEHR::AssumedLibraryTypes::TimeDefinitions

Included in:
ISO8601DateModule, ISO8601DurationModule, ISO8601TimeModule
Defined in:
lib/open_ehr/assumed_library_types.rb

Overview

end of Interval

Constant Summary collapse

DAYS_IN_LEAP_YEAR =

< Any

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

Returns:

  • (Boolean)


105
106
107
108
109
110
111
112
113
# File 'lib/open_ehr/assumed_library_types.rb', line 105

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

Returns:

  • (Boolean)


115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/open_ehr/assumed_library_types.rb', line 115

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

Returns:

  • (Boolean)


128
129
130
# File 'lib/open_ehr/assumed_library_types.rb', line 128

def self.valid_minute?(mi)
  mi >= 0 and mi < MINUTES_IN_HOUR
end

.valid_month?(mo) ⇒ Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/open_ehr/assumed_library_types.rb', line 136

def self.valid_month?(mo)
  mo >= 1 and mo <= MONTH_IN_YEAR
end

.valid_second?(s) ⇒ Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/open_ehr/assumed_library_types.rb', line 132

def self.valid_second?(s)
  s >= 0 and s < SECONDS_IN_MINUTE
end

.valid_year?(year) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/open_ehr/assumed_library_types.rb', line 101

def self.valid_year?(year)
  return !year.nil? && year >= 0
end