Validating datetime

It seems like something that should exist already, so I'd just like to check before I attempt my own version...

Cheers, Mark It should be reasonably straight forward to add a validates_date_time method to my plugin. Is there a particular reason that validates_date and validates_time doesn't use the above method for Date and Time? Date.parse(value_before_type_cast.to_s) Rescue I've messed around with the plugin and got it doing something approaching what I need, but it's not very tidy yet.

import re from ifware.calendar import days_in_month def get_integers(alist): result = [] for x in alist: try: result.append(int(x)) except Value Error: result.append(0) return result # A regular expression that matches timestamps. ' # Tenths of milliseconds (may follow seconds when present) r')? ' # Timezone (optional) r'$' ) def parse_time(timestamp): matches = ts_regex.findall(timestamp) if len(matches) parse_time() expects one parameter, which is the timestamp that needs to be validated.

ts_regex = re.compile( r'^' r'(\d)' # Year (4 digits) r'(\d)' # Month r'(\d)' # Day r'(\d)' # Hour r'(\d)' # Minute r'(? If it detects an invalid timestamp component, it raises a Value Error exception; otherwise, it returns the components of the timestamp.

Announcement (2017-05-07): now read-only since I unfortunately do not have the time to support and maintain the forum any more.

Please see and for other Rails- und Ruby-related community platforms.

It calls the days_in_month() function to obtain the number of days in the specified month.

validating datetime-18validating datetime-7validating datetime-28

A regular expression is nothing more than a pattern of characters itself, matched against a certain parcel of text.The learning curve for Regular expression may not be very easy for everyone.Often this results in to underutilization of Regular Expression and true power are not harnessed.UUsing Regular Expressions, it is simple to search for a specific word or string of characters.Almost every editor on every computer system can do this.

Leave a Reply