Skip to content

Instantly share code, notes, and snippets.

@khooz
Created November 29, 2015 19:16
Show Gist options
  • Save khooz/e3ab591393db8a98c626 to your computer and use it in GitHub Desktop.
Save khooz/e3ab591393db8a98c626 to your computer and use it in GitHub Desktop.
PCRE compatible regex tester for Persian date-time. It differs from Gregorian and Julian in the way that the first 6 months of the year (spring and summer) has 31 days in and the other 6 (autumn and winter) has 30 days. The last month of winter (Esfand) has a leap day every four years and this is accounted in this regex. The seconds does not cou…
(?(DEFINE)(?<delim_date>\/)(?<delim_time>:)(?<delim_datetime>-)(?<delim_fractime>\.)(?<delim_ampm> ))^(?:\d{4}(?&delim_date)(?:0*[1-6](?&delim_date)0*(?:[1-9]|[1-2]\d|3[01])|0*(?:[7-9]|1[01])(?&delim_date)0*(?:[1-9]|[1-2]\d|30))|\d{4}(?&delim_date)0*12(?&delim_date)0*(?:[1-9]|[1-2]\d)|\d{2}(?:[02468][37]|[13579][159])(?&delim_date)0*12(?&delim_date)0*30)(?:(?&delim_datetime)(?:0*(?:\d|1\d|2[0-3])(?&delim_time)0*(?:\d|[1-5]\d)(?&delim_time)0*(?:\d|[1-5]\d)(?:(?&delim_fractime)\d+)?(?!(?&delim_ampm)(?i)(?:AM|PM)(?-i))|0*(?:\d|1[0-2])(?&delim_time)0*(?:\d|[1-5]\d)(?&delim_time)0*(?:\d|[1-5]\d)(?:(?&delim_fractime)\d+)?(?&delim_ampm)(?i)(?:AM|PM)(?-i)))?$
@khooz
Copy link
Author

khooz commented Nov 29, 2015

PCRE compatible regex tester for Persian date-time. It differs from Gregorian and Julian in the way that the first 6 months of the year (spring and summer) has 31 days in and the other 6 (autumn and winter) has 30 days. The last month of winter (Esfand) has a leap day every four years and this is accounted in this regex. The seconds does not count for leap seconds as the result of UTC correction. It also doesn't count for DST as these settings are not a must in calendar and is of the issue of desire and application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment