It would be easier to standardize the input so you only have to run one regular expression check to validate and then split the data up. On Wed, Jul 1, 2009 at 10:33 AM, Ashley Sheridan <ash@xxxxxxxxxxxxxxxxxxxx>wrote: > On Wednesday 01 July 2009 16:25:29 Matt Neimeyer wrote: > > I haven't been able to find anything by googling... Does anyone know > > of any libraries that will split up date ranges? We've got a project > > where "Date Of Attendance" is moving from a single type in character > > field to an automatically built field based on a DateBegin date field > > and a DateEnd date field. Some examples of what I'd like ideally... > > > > Given: July 19-22, 2009 > > Return: 7/19/2009 and 7/22/2009 > > > > Given: July 19th and 20th > > Return: 7/19/2009 and 7/20/2009 (we can safely assume current year for > > this project) > > > > Given: Sept 19, 2009 - Sept 22, 2009 > > Return: 9/19/2009 and 9/22/2009 > > > > Given: July 19th, 2009 > > Return: 7/19/2009 and 7/19/2009 > > > > Given: 7/19/2009 > > Return: 7/19/2009 and 7/19/2009 > > > > I could probably hack something together that would work most of the > > time... but why reinvent the wheel if some poor shlub has already done > > it. > > > > If such a thing doesn't exist... then I'm considering an algorithm > > like such... (and advice... yays and nays are appreciated) > > > > Replace the names (and variations thereof) of the months with their > > numeric equivilants followed by a comma. So the above would become... > > > > 7, 19-22, 2009 > > 7, 19th and 20th > > 9, 19, 2009 - 9, 22, 2009 > > 7, 19th, 2009 > > 7/19/2009 > > > > Then replace all the th and nd and st with nothing... replace all the > > ands with a dash... and eliminate spaces... and change / to , > > Giving... > > > > 7,19-22,2009 > > 7,19-20 > > 9,19,2009-9,22,2009 > > 7,19,2009 > > 7,19,2009 > > > > Then explode on commas. If you have two elements populate the third > > with the current year. (This "fixes" 7,19-20 to 7,19-20,2009). Not a > > given example, but it would also fix 7/19 to 7,19,2009. > > > > When you have three elements then you have a "valid" date. Loop over > > each element and populate begin and end, if you find a dash in the > > current element then split on the dash and populate as needed. Yes > > this would allow 7-8,19-20,2009 to create 7/19/2009 and 8/20/2009 but > > I think its as safe as any assumption that "regular people" wouldn't > > enter that as a date range. > > > > If you have more than three elements then split on the dash and as > > long as you have have only two elements then consider each item by > > itself. > > > > If it's not handled by the above rules then don't split it up. > > > > Thanks in advance. > > > > Matt > > Wow, first question is, why accept such a variety of inputs? Can't you > force a > particular standard for people that allows them to enter a range? > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- - Adam Shannon ( http://ashannon.us )