5 kyu
Regex for Gregorian date validation
184 of 278kolichj
Loading description...
Strings
Regular Expressions
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Python, possibly other languages: tests miss sanity checks on values provided by user solution and crash badly when an unexpected value (not a pattern, or not a valid pattern) is returned.
Related: https://www.codewars.com/kata/5ab23a9c1cec39668c000055/discuss#62c2112ef8f15c004b4c4f1e
For solving in python, I'm not sure where am I making mistake when outputting return. I get:" raise TypeError("first argument must be string or compiled pattern")" error?
This comment has been hidden.
it shows me expected '01.02.2009' to match... at All possible days (10000 tests) section, but my regex really matches it.
may i see your regexp?
This comment has been hidden.
Try to use tools like debuggex: https://www.debuggex.com/r/xN8wfXZE1Y4Qd3MO
It shows that your regexp matches two numbers and two any symbols, like this:
"11xx"
point "." match any symbol
My Regex didn't displayed very well as i sayed above, My full regex here: https://www.debuggex.com/r/bPKdkJfQVfnkQRay
This comment has been hidden.
In the Python version, one of the sample tests prints out a different input than the actual input. Fork here
mark resolved
The code limit is too high. If someone would try to harcode it, it would take thousands of characters. I barely hit the limit even though I didn't hardcode the date.
too "tight", you mean?
Yes. I was confused between saying too "low" or too "high", because it could be interpreted either way.
Since this kata also tests for dates before the introduction of the Gregorian calendar in 1582 the description should state this somewhere or at least mention the use of the proleptic Gregorian calendar.
The tests should be much more rigorous, probably checking every date from
01.01.0001
till some point in 21 century. For example, using the snippet provided below, this solution fails 36k times, this one fails 276k times etc.The anticheat is not good enough.
This comment has been hidden.
Dang, I got the regex down to 192 characters but the thing I need to shorten it more isn't working.
This comment has been hidden.
Can someone tell how exactly should I write code in Python, I wrote a function which returns either True or False. In the terminal test cases work correct , but whenever I run in codewars , it says "True should equal False" even though program in fact returns False
No need to write python code. Its regexp kata, you should edit this regexp string:
@fred_fred_123, you've probably just misead the logs. The log appears above the test result, not below it. Hope that helps!
Thanks , will consider in the future
Why are 29.02.0100 incorrect year? 100%4 == 0
Read the wiki!
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400. For example, the years 1700, 1800, and 1900 are not leap years, but the year 2000 is.
Oh, thanks for your answer.
you can do this in one line by datetime.datetime.strptime("","%d-%m-%Y")
The point of this cata is regexp practice and understanding Gregorian calendar.
0th year is false, why?
In the AD year numbering system, whether applied to the Julian or Gregorian calendars, AD 1 is preceded by 1 BC. There is no year "0" between them, so a new century begins in a year which has "01" as the final digits (e.g., 1801, 1901, 2001).
https://en.wikipedia.org/wiki/Anno_Domini#No_year_zero_/_Start_and_end_of_a_century
JavaScript version needs
Object.freeze(RegExp.prototype)
inPreloaded
.. I'd have put it in for you but I can't edit.Done, thanks a lot!
.
Need to put in
31.03.0000
as a fixed test as well probably ( revalidation is not done over random tests ).And you need not assign it ( though it shouldn't hurt ); you can just put
Object.freeze(RegExp.prototype);
and discard the return value. That's how it's normally done, it freezes in place.Hmm.. It seems revalidation was delayed, but now it's done.
suggestions:
display the tested string and the expected value, because there is no
print
available for the user:test.it('Testing: %s, expecting: %s' % (input, expected))
I encountered this error message:
Well, 31.12. is not August... (which is spelt with a capital "A", like all months...)
are you supposed to check for leap years as well? because then it will get very messy...
Yes, that's the point of the kata. ;) But it should be plainly told in the description, though, yes.
With a regexp? I don't doubt it can be done, but I wonder...
I felt the same at the beginning. ;) And then... I choose to use a "shortcut" (well, manner of speaking! :o )
I mean, I'm at ~180 characters, and I would still need to filter incorrect leap years... and you can't even use the verbose format of regex :-(
only 180...? ;)
This comment has been hidden.
This comment has been hidden.
Yes, I still have a lot to learn about regex :-)
This comment has been hidden.
@kolichj
Please see my original suggestions/issues@anter69, yes, i'll fix them tomorrow. Anyway, it's my first kata, i'm not very familiar with test cases. Will kata lose approved status if i edit it?
@anter69 yes, i'll fix them tomorrow. Anyway, it's my first kata, i'm not very familiar with test cases. Will kata lose approved status if edited?
No, nothing wrong with editing (improving) katas, so go ahead!
This comment has been hidden.
This comment has been hidden.
Well done!
Very interesting one. Though, should we consider this as a problem or not??
Hmmm. It seems i should limit length of validator up to 400 characters.
fixed.