Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit ranges of dates to the parse_range() method #1

Merged
merged 6 commits into from Sep 21, 2012

Conversation

zostay
Copy link
Contributor

@zostay zostay commented Sep 19, 2012

These changes add a number of improvements to Date::RangeParser::EN:

  • Allows for explicit ranges separated by " to ", " thru ", " through ", " - " (I did not implement "between "..." and "... because "between" may imply an exclusive range, which I didn't want to mess with)
  • Fixes a couple small warnings about undefined values when a bare month us used
  • Gives Date::Manip the same now handling via the now_callback that the Date::RangeParser::EN uses by setting ForceDate
  • Changed the way Date::Manip is used so that we try to use the DM6 OO interface when available or the DM5 when needed (or requested)
  • Adds a test for the DM5/DM6 bit (which skips if you have Date::Manip 6.00 - 6.13 because DM5 backwards compatibility was added in 6.14)
  • Adds more tests for date ranges and some examples of the new ranges
  • Documents more formally the kinds of date range terms it understands

I think that's about it.

I adjusted the TODO section of the POD, which imposes some of my own opinions on the project, but feel free to edit my opinions and strike anything you like from the record.

Sterling Hanenkamp added 6 commits September 19, 2012 11:36
For the rest of the changes coming, we will need to use the ForceDate option of
Date::Manip to make sure the date context is setup correctly using the
now_callback. Unfortunately, with the functional interface, you can only set
ForceDate globally (not per-call). It would be better, therefore, to use the OO
interface which allows per-object configuration. However, this is only available
in 6.00+, so add a helper method to bridge either interface.

When using the older functional interface (either because the developer uses a
version of Date::Manip older than 6.00 or because they are using 6.14+ with
backend set to "DM5"), we will record the previous ForceDate setting, force the
date while we make the call, and then flip it back to the previous setting.

If the version of Date::Manip can be tested with DM5 turned one, this adds a
test to make sure the ForceDate setting is reverted after each use.
This is implemented in terms of parsing the range recursively, so the
performance of this is not as good as it probably could be since we end up
constructing additional dates that we throw away. However, it does the job and,
unless I'm mistaken, the parsing should proceed in such a way that you will
always reach a base case with any input.
@mjaquilina
Copy link
Owner

Thanks, Sterling!

This looks awesome at first glance. I'll do some testing tonight and, provided there are no issues, will pull and release to CPAN this evening.

mjaquilina added a commit that referenced this pull request Sep 21, 2012
Add explicit ranges of dates to the parse_range() method
@mjaquilina mjaquilina merged commit 9b42115 into mjaquilina:master Sep 21, 2012
afresh1 added a commit to GrantStreetGroup/Date-RangeParser-EN that referenced this pull request Oct 20, 2023
Merge in GITHUB/date-rangeparser-en from Updates-for-0.9 to master

* commit 'fcd105682f57d1cf16f257371bb76676c7f99fd5': (39 commits)
  Attribute MAq as an author
  Switch to Dist::Zilla::PluginBundle::Author::GSG
  Remove .perl-version
  Tidy up cpanfile
  Update META yml with version and author
  Add Verion and Authority to main file
  Fix business day logic beginning date bugs
  Change maintained by line
  Update POD
  Rearrange elsif portions
  Condense conditional statements
  Fix spacing issues
  Regroup last|past together
  Improve Dashed Date regex
  Add todo for all zeros case
  last and past mintues and hours start and end at BOD, EOD
  Condense next hours minute seconds logic
  Make wider use of EOD instead of adding one day and subtracting a second
  Business day logic autocompletes with incomplete array
  Condense past hours minutes and seconds to one subroutine
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants