Skip to content

Commit

Permalink
add api date time regular expressions
Browse files Browse the repository at this point in the history
also add helper method to create error reports

refs CNVS-10087
refs CNVS-9618

test plan
 - specs should pass

Change-Id: I74f40dd16a85a0d95f9b152f6750ec98aade2ba5
Reviewed-on: https://gerrit.instructure.com/33114
Tested-by: Jenkins <[email protected]>
Reviewed-by: Anthus Williams <[email protected]>
Product-Review: Rob Orton <[email protected]>
QA-Review: Rob Orton <[email protected]>
  • Loading branch information
roor0 committed Apr 10, 2014
1 parent 278d282 commit 052509f
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions lib/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -548,18 +548,29 @@ def self.value_to_array(value)
value.is_a?(String) ? value.split(',') : (value || [])
end

def self.invalid_time_stamp_error(attribute, message)
ErrorReport.log_error('invalid_date_time',
message: "invalid #{attribute}",
exception_message: message)
end

def valid_iso8601?(date_time)
iso8601 = /^(?<year>-?[0-9]{4})-
(?<month>1[0-2]|0[1-9])-
(?<day>3[0-1]|0[1-9]|[1-2][0-9])T
(?<hour>2[0-3]|[0-1][0-9]):
(?<minute>[0-5][0-9]):
(?<second>60|[0-5][0-9])
(?<fraction>\.[0-9]+)?
(?<timezone>Z|[+-](?:2[0-3]|[0-1][0-9]):[0-5][0-9])?$/x
date_time.to_s =~ iso8601
date_time.to_s =~ ISO8601_REGEX
end

# regex for valid iso8601 dates
ISO8601_REGEX = /^(?<year>-?[0-9]{4})-
(?<month>1[0-2]|0[1-9])-
(?<day>3[0-1]|0[1-9]|[1-2][0-9])T
(?<hour>2[0-3]|[0-1][0-9]):
(?<minute>[0-5][0-9]):
(?<second>60|[0-5][0-9])
(?<fraction>\.[0-9]+)?
(?<timezone>Z|[+-](?:2[0-3]|[0-1][0-9]):[0-5][0-9])?$/x

# regex for valid dates
DATE_REGEX = /^\d{4}[- \/.](0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])$/

# regex for shard-aware ID
ID = '(?:\d+~)?\d+'

Expand Down

0 comments on commit 052509f

Please sign in to comment.