Changeset 81 for ruby/trunk/lib/models/assumed_library_types.rb
- Timestamp:
- Jul 17, 2008, 11:02:57 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ruby/trunk/lib/models/assumed_library_types.rb
r80 r81 1 1 require 'date' 2 require 'time' 2 3 3 4 module OpenEHR … … 90 91 valid_minute?(m) and valid_second?(s) and ((h >= 0 and h < HOURS_IN_DAY) or (h == HOURS_IN_DAY and m == 0 and s == 0)) 91 92 end 92 def self.valid_minute?(m )93 m >= 0 and m< MINUTES_IN_HOUR93 def self.valid_minute?(mi) 94 mi >= 0 and mi < MINUTES_IN_HOUR 94 95 end 95 96 def self.valid_second?(s) 96 97 s >= 0 and s < SECONDS_IN_MINUTE 97 98 end 98 def self.valid_month?(m )99 m >= 1 and m<= MONTH_IN_YEAR99 def self.valid_month?(mo) 100 mo >= 1 and mo <= MONTH_IN_YEAR 100 101 end 101 102 end # end of TIME_DEFINITIONS … … 148 149 month_unknown? or day_unknown? 149 150 end 150 def valid_iso8601_date(string)151 def self.valid_iso8601_date?(string) 151 152 begin 152 date =Date.parse(string)153 Date.parse(string) 153 154 rescue 154 155 return false … … 160 161 161 162 class ISO8601_TIME < TIME_DEFINITIONS 162 163 attr_reader :hh, :mm, :ss, :msec, :tz 164 def initialize(hh = nil, mm = nil, ss = nil, msec = nil, tz = nil) 165 166 end 167 def as_string 168 s = @hh 169 if !@mm.nil? 170 s += ":" + @mm 171 if !@ss.nil? 172 s += ":" + @ss 173 if !@msec.nil? 174 s += "," + @msec 175 if !@tz.nil? 176 s += @tz 177 end 178 end 179 end 180 end 181 s 182 end 183 def self.valid_iso8601_time?(s) 184 if /(\d{2}):?(\d{2})?(:?)(\d{2})?((\.|,)(\d+))?(Z|([+-](\d{2}):?(\d{2})))?/ =~ s 185 # ISO 8601 regular expression by H. Yuki 186 # http://digit.que.ne.jp/work/wiki.cgi?Perl%E3%83%A1%E3%83%A2%2FW3C%E5%BD%A2%E5%BC%8F%E3%81%AE%E6%97%A5%E6%99%82%E3%81%AE%E8%A7%A3%E6%9E%90 187 # (\d{4})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d))?)?(Z|([+-]\d{2}):(\d{2}))?)?)?)? 188 hh = $1; mm = $2; ss = $4; msec = $7; tz = $8 189 if hh.to_i == HOURS_IN_DAY and (mm.nil? or mm.to_i == "00") and (ss.nil? or ss.to_i == "00") 190 return true 191 end 192 if hh.nil? or (hh.to_i < 0 or hh.to_i >= HOURS_IN_DAY) 193 return false 194 end 195 if !mm.nil? 196 if !self.valid_minute?(mm.to_i) 197 return false 198 end 199 end 200 if !ss.nil? 201 if !self.valid_second?(ss.to_i) 202 return false 203 end 204 end 205 if !tz.nil? and tz != "Z" 206 if /[+-](\d{2}):?(\d{2})/ =~ tz 207 h = $1; m = $2 208 if h.to_i < 0 or h.to_i >= HOURS_IN_DAY 209 return false 210 end 211 if m.to_i < 0 or m.to_i >= MINUTES_IN_HOUR 212 return false 213 end 214 else 215 return false 216 end 217 end 218 return true 219 else 220 return false 221 end 222 end 163 223 end # end of ISO8601_TIME 164 224
Note:
See TracChangeset
for help on using the changeset viewer.