Re: [PHP] Another date exercise

2009-08-19 Thread tedd

At 10:43 AM -0500 8/19/09, Shawn McKenzie wrote:

 > First stab at it.  Of course it needs US date ordering (month day year).

  You can't do euro type dates or any other format because there is no
 way to tell the difference between 1/2/2009 (January) and 1/2/2009
 (February):

 



Guess you didn't like this one?  Also, if you change the / to - in the
preg_replace() it should work on Euro style dates.

$date = preg_replace("#([\d])+[^-\d]+([\d]+)[^-\d]+([\d]+)#",
"$1-$2-$3", $date);

-Shawn


-Shawn:

Thanks, but my idea was more along the lines of this:

http://php1.net/b/date-picker/index.php

It's not thoroughly tested, but thus far it works.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Another date exercise

2009-08-19 Thread Luke
2009/8/19 Shawn McKenzie 

> Shawn McKenzie wrote:
> > tedd wrote:
> >> At 3:40 PM +0530 8/17/09, kranthi wrote:
> >>> dont you think http://in3.php.net/strtotime is a solution to your
> >>> problem ?
> >> No, it's not a solution to my problem -- I have he problem solved.
> >>
> >> I was just asking if anyone wanted to submit their php solution. It was
> >> only an exercise.
> >>
> >> I know there are numerous javascript solutions (some good, some bad),
> >> but ALL of their data has to be accepted and scrubbed by a php script
> >> anyway, so I was suggesting creating a php script to do it.
> >>
> >> If it's not a good exercise, then don't do it.
> >
> > First stab at it.  Of course it needs US date ordering (month day year).
> >  You can't do euro type dates or any other format because there is no
> > way to tell the difference between 1/2/2009 (January) and 1/2/2009
> > (February):
> >
> >  >
> > $dates = array(
> > 'August 5, 2009',
> > 'Aug 05 2009',
> > 'Aug 5, 9',
> > '08/05/09',
> > '8-5-9',
> > '8 05 2009',
> > '8,5,9',);
> >
> > foreach($dates as $date) {
> > $date = preg_replace("#([\d])+[^/\d]+([\d]+)[^/\d]+([\d]+)#",
> > "$1/$2/$3", $date);
> > echo date("M j, Y", strtotime($date)) ."\n";
> > }
> >
> > ?>
> >
>
> Guess you didn't like this one?  Also, if you change the / to - in the
> preg_replace() it should work on Euro style dates.
>
> $date = preg_replace("#([\d])+[^-\d]+([\d]+)[^-\d]+([\d]+)#",
> "$1-$2-$3", $date);
>
> -Shawn
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Perhaps you could detect the region of the user to pick which kind of date
to use

-- 
Luke Slater
:O)

this text is protected by international copyright. it is illegal for
anybody apart from the recipient to keep a copy of this text.
dieser text wird von internationalem urheberrecht geschuetzt. allen
ausser dem/der empfaenger/-in ist untersagt, eine kopie dieses textes
zu behalten.


Re: [PHP] Another date exercise

2009-08-19 Thread Shawn McKenzie
Shawn McKenzie wrote:
> tedd wrote:
>> At 3:40 PM +0530 8/17/09, kranthi wrote:
>>> dont you think http://in3.php.net/strtotime is a solution to your
>>> problem ?
>> No, it's not a solution to my problem -- I have he problem solved.
>>
>> I was just asking if anyone wanted to submit their php solution. It was
>> only an exercise.
>>
>> I know there are numerous javascript solutions (some good, some bad),
>> but ALL of their data has to be accepted and scrubbed by a php script
>> anyway, so I was suggesting creating a php script to do it.
>>
>> If it's not a good exercise, then don't do it.
> 
> First stab at it.  Of course it needs US date ordering (month day year).
>  You can't do euro type dates or any other format because there is no
> way to tell the difference between 1/2/2009 (January) and 1/2/2009
> (February):
> 
>  
> $dates = array(
> 'August 5, 2009',
> 'Aug 05 2009',
> 'Aug 5, 9',
> '08/05/09',
> '8-5-9',
> '8 05 2009',
> '8,5,9',);
> 
> foreach($dates as $date) {
> $date = preg_replace("#([\d])+[^/\d]+([\d]+)[^/\d]+([\d]+)#",
> "$1/$2/$3", $date);
> echo date("M j, Y", strtotime($date)) ."\n";
> }
> 
> ?>
> 

Guess you didn't like this one?  Also, if you change the / to - in the
preg_replace() it should work on Euro style dates.

$date = preg_replace("#([\d])+[^-\d]+([\d]+)[^-\d]+([\d]+)#",
"$1-$2-$3", $date);

-Shawn

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Another date exercise

2009-08-17 Thread Shawn McKenzie
tedd wrote:
> At 3:40 PM +0530 8/17/09, kranthi wrote:
>> dont you think http://in3.php.net/strtotime is a solution to your
>> problem ?
> 
> No, it's not a solution to my problem -- I have he problem solved.
> 
> I was just asking if anyone wanted to submit their php solution. It was
> only an exercise.
> 
> I know there are numerous javascript solutions (some good, some bad),
> but ALL of their data has to be accepted and scrubbed by a php script
> anyway, so I was suggesting creating a php script to do it.
> 
> If it's not a good exercise, then don't do it.

First stab at it.  Of course it needs US date ordering (month day year).
 You can't do euro type dates or any other format because there is no
way to tell the difference between 1/2/2009 (January) and 1/2/2009
(February):




-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Another date exercise

2009-08-17 Thread Luke
2009/8/17 Luke 

>
>
> 2009/8/17 tedd 
>
>> At 4:10 PM +0100 8/17/09, Luke wrote:
>>
>>  What would be really cool is if someone wrote a PHP script that generates
>>> some Javascript code that could do this.
>>>
>>> I mean while we're on the subject of complicating things ;)
>>>
>>> --
>>> Luke Slater
>>> :O)
>>>
>>
>> While writing/creating javascript from php can be done, that's not the
>> problem.
>>
>> The problem is that the data provided from a javascript program that
>> cannot be trusted. All data taken from javascript routines must be
>> sanitized.
>>
>> So if you want to talk about complicating things, start accepting data
>> from javascript routines without sanitizing and see how that works out for
>> you.
>>
>>
>> Cheers,
>>
>> tedd
>>
>> --
>> ---
>> http://sperling.com  http://ancientstones.com  http://earthstones.com
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
> I didn't say anything about accepting unsanitized data now did I?
>
>
> --
> Luke Slater
> :O)
>
> this text is protected by international copyright. it is illegal for
> anybody apart from the recipient to keep a copy of this text.
> dieser text wird von internationalem urheberrecht geschuetzt. allen
> ausser dem/der empfaenger/-in ist untersagt, eine kopie dieses textes
> zu behalten.
>

Sorry to annoy you Tedd,

I guess stage one would be something like

$date = $_GET['datestring'];
$exploded_date = explode(' ', $date);

foreach($exploded_date as $constituent)
{
if(preg_match('/^{1,31}$/', $constituent))
{
$sane_date["day"] = $constituent;
}
}

Then in the foreach loop would also be something that would check for months
and years, setting the constituent to $sane_date["month"] and
$sane_date["year"] respectively.

Something like that?

I would try it out but I'm at work ;)

-- 
Luke Slater
:O)

this text is protected by international copyright. it is illegal for
anybody apart from the recipient to keep a copy of this text.
dieser text wird von internationalem urheberrecht geschuetzt. allen
ausser dem/der empfaenger/-in ist untersagt, eine kopie dieses textes
zu behalten.


Re: [PHP] Another date exercise

2009-08-17 Thread Luke
2009/8/17 tedd 

> At 4:10 PM +0100 8/17/09, Luke wrote:
>
>> What would be really cool is if someone wrote a PHP script that generates
>> some Javascript code that could do this.
>>
>> I mean while we're on the subject of complicating things ;)
>>
>> --
>> Luke Slater
>> :O)
>>
>
> While writing/creating javascript from php can be done, that's not the
> problem.
>
> The problem is that the data provided from a javascript program that cannot
> be trusted. All data taken from javascript routines must be sanitized.
>
> So if you want to talk about complicating things, start accepting data from
> javascript routines without sanitizing and see how that works out for you.
>
>
> Cheers,
>
> tedd
>
> --
> ---
> http://sperling.com  http://ancientstones.com  http://earthstones.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
I didn't say anything about accepting unsanitized data now did I?

-- 
Luke Slater
:O)

this text is protected by international copyright. it is illegal for
anybody apart from the recipient to keep a copy of this text.
dieser text wird von internationalem urheberrecht geschuetzt. allen
ausser dem/der empfaenger/-in ist untersagt, eine kopie dieses textes
zu behalten.


Re: [PHP] Another date exercise

2009-08-17 Thread tedd

At 4:10 PM +0100 8/17/09, Luke wrote:
What would be really cool is if someone wrote a PHP script that 
generates some Javascript code that could do this.


I mean while we're on the subject of complicating things ;)

--
Luke Slater
:O)


While writing/creating javascript from php can be done, that's not the problem.

The problem is that the data provided from a javascript program that 
cannot be trusted. All data taken from javascript routines must be 
sanitized.


So if you want to talk about complicating things, start accepting 
data from javascript routines without sanitizing and see how that 
works out for you.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Another date exercise

2009-08-17 Thread Luke
2009/8/17 tedd 

> At 4:22 PM -0400 8/16/09, Paul M Foster wrote:
>
>> On Sun, Aug 16, 2009 at 08:36:17AM +0100, Lester Caine wrote:
>> -snip-
>>  > But as has been said, the real solution is a date picker.
>>
>> I *hate* date pickers. They slow down input. I can type 082309
>> faster than I can ever do it with a date picker. The date class knows
>> I'm in America and since it's a six-digit date, it must be mmddyy. (Yes,
>> for those of you *not* in America, I agree our dates are goofy. I think
>> we all ought to be on the metic system, too, but America and the UK seem
>> intent on sticking to Imperial measure.)
>>
>> Paul
>>
>
>
> Paul:
>
> Yes, that's part of the problem. I was suggesting an exercise where people
> could put their collective heads together and create a php solution.
>
> I realize that US has DD, MM,  and the Euros have , MM, DD and
> others have other things (i.e., Year of the York).
>
> Not addressing the "other things" -- to me, if one uses a character for a
> month, then there's no problem in deciphering any entry regardless of
> format.
>
> For example, 2009 Aug 23, or Aug 23 2009, or Aug 2009 23, or 23 2009 Aug,
> -- they could all be entered in whatever order you want and deciphered
> correctly. The rules of course are:
>
> Year must be in thousands -- 1000-5000.
> Month must be a character -- D for December, May for May, Jun for June and
> so on.
> Day must be in ones or tens -- 1 or 09, or 31.
>
> It's certainly not a problem to write such code, I only suggested the
> exercise to get people to expound on the problems they encountered. Instead,
> I received "use javascript". Okay... but that's not a php solution, right?
>
> Cheers,
>
> tedd
>
> --
> ---
> http://sperling.com  http://ancientstones.com  http://earthstones.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
What would be really cool is if someone wrote a PHP script that generates
some Javascript code that could do this.

I mean while we're on the subject of complicating things ;)

-- 
Luke Slater
:O)

this text is protected by international copyright. it is illegal for
anybody apart from the recipient to keep a copy of this text.
dieser text wird von internationalem urheberrecht geschuetzt. allen
ausser dem/der empfaenger/-in ist untersagt, eine kopie dieses textes
zu behalten.


Re: [PHP] Another date exercise

2009-08-17 Thread tedd

At 4:22 PM -0400 8/16/09, Paul M Foster wrote:

On Sun, Aug 16, 2009 at 08:36:17AM +0100, Lester Caine wrote:
-snip-
 > But as has been said, the real solution is a date picker.

I *hate* date pickers. They slow down input. I can type 082309
faster than I can ever do it with a date picker. The date class knows
I'm in America and since it's a six-digit date, it must be mmddyy. (Yes,
for those of you *not* in America, I agree our dates are goofy. I think
we all ought to be on the metic system, too, but America and the UK seem
intent on sticking to Imperial measure.)

Paul



Paul:

Yes, that's part of the problem. I was suggesting an exercise where 
people could put their collective heads together and create a php 
solution.


I realize that US has DD, MM,  and the Euros have , MM, DD 
and others have other things (i.e., Year of the York).


Not addressing the "other things" -- to me, if one uses a character 
for a month, then there's no problem in deciphering any entry 
regardless of format.


For example, 2009 Aug 23, or Aug 23 2009, or Aug 2009 23, or 23 2009 
Aug, -- they could all be entered in whatever order you want and 
deciphered correctly. The rules of course are:


Year must be in thousands -- 1000-5000.
Month must be a character -- D for December, May for May, Jun for 
June and so on.

Day must be in ones or tens -- 1 or 09, or 31.

It's certainly not a problem to write such code, I only suggested the 
exercise to get people to expound on the problems they encountered. 
Instead, I received "use javascript". Okay... but that's not a php 
solution, right?


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Another date exercise

2009-08-17 Thread tedd

At 3:40 PM +0530 8/17/09, kranthi wrote:

dont you think http://in3.php.net/strtotime is a solution to your problem ?


No, it's not a solution to my problem -- I have he problem solved.

I was just asking if anyone wanted to submit their php solution. It 
was only an exercise.


I know there are numerous javascript solutions (some good, some bad), 
but ALL of their data has to be accepted and scrubbed by a php script 
anyway, so I was suggesting creating a php script to do it.


If it's not a good exercise, then don't do it.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Another date exercise

2009-08-17 Thread kranthi
dont you think http://in3.php.net/strtotime is a solution to your problem ?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Another date exercise

2009-08-16 Thread Ralph Deffke
i agree on date pickers and js is  well

use individual fields for day month and year, make month and year as drop
down and u have no problem at all

make live easier

ralph

"Paul M Foster"  wrote in message
news:20090816202217.gs2...@quillandmouse.com...
> On Sun, Aug 16, 2009 at 08:36:17AM +0100, Lester Caine wrote:
>
> > tedd wrote:
> >> Hi gang:
> >>
> >> Here's another exercise to consider.
> >>
> >> This is a date entry problem where the user can enter a date in various
> >> forms, but the return will be in a consistent format.
> >>
> >> For example, a user might enter a date in the form of:
> >>
> >> August 5, 2009
> >> Aug 05 2009
> >> Aug 5, 9
> >> 08/05/09
> >> 8-5-9
> >> 8 05 2009
> >> 8,5,9
> >>
> >> Or any combination thereof.
> >>
> >> However, the resultant date will be standardized to: Aug 5, 2009.
> >>
> >> Extra points for solving this for Euro as well as US date formats
(i.e.,
> >> 5 Aug, 2009 vs Aug 5, 2009).  And, extra extra points for accommodating
> >> month brevity, such as "A" for August and "Mar" for March and so on.
> >
> > But the real problem here is 05/08/09 is still August 5 2009 .
> > So teaching customers to use 2009.08.05 removes the hassle of needing to
> > know
> > where your target site is based!
> >
> > But as has been said, the real solution is a date picker.
>
> I *hate* date pickers. They slow down input. I can type 082309
> faster than I can ever do it with a date picker. The date class knows
> I'm in America and since it's a six-digit date, it must be mmddyy. (Yes,
> for those of you *not* in America, I agree our dates are goofy. I think
> we all ought to be on the metic system, too, but America and the UK seem
> intent on sticking to Imperial measure.)
>
> Paul
>
>
> -- 
> Paul M. Foster



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Another date exercise

2009-08-16 Thread Paul M Foster
On Sun, Aug 16, 2009 at 08:36:17AM +0100, Lester Caine wrote:

> tedd wrote:
>> Hi gang:
>>
>> Here's another exercise to consider.
>>
>> This is a date entry problem where the user can enter a date in various
>> forms, but the return will be in a consistent format.
>>
>> For example, a user might enter a date in the form of:
>>
>> August 5, 2009
>> Aug 05 2009
>> Aug 5, 9
>> 08/05/09
>> 8-5-9
>> 8 05 2009
>> 8,5,9
>>
>> Or any combination thereof.
>>
>> However, the resultant date will be standardized to: Aug 5, 2009.
>>
>> Extra points for solving this for Euro as well as US date formats (i.e.,
>> 5 Aug, 2009 vs Aug 5, 2009).  And, extra extra points for accommodating
>> month brevity, such as "A" for August and "Mar" for March and so on.
>
> But the real problem here is 05/08/09 is still August 5 2009 .
> So teaching customers to use 2009.08.05 removes the hassle of needing to 
> know
> where your target site is based!
>
> But as has been said, the real solution is a date picker.

I *hate* date pickers. They slow down input. I can type 082309
faster than I can ever do it with a date picker. The date class knows
I'm in America and since it's a six-digit date, it must be mmddyy. (Yes,
for those of you *not* in America, I agree our dates are goofy. I think
we all ought to be on the metic system, too, but America and the UK seem
intent on sticking to Imperial measure.)

Paul


-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Another date exercise

2009-08-16 Thread Ashley Sheridan
On Sun, 2009-08-16 at 08:36 +0100, Lester Caine wrote:
> tedd wrote:
> > Hi gang:
> > 
> > Here's another exercise to consider.
> > 
> > This is a date entry problem where the user can enter a date in various 
> > forms, but the return will be in a consistent format.
> > 
> > For example, a user might enter a date in the form of:
> > 
> > August 5, 2009
> > Aug 05 2009
> > Aug 5, 9
> > 08/05/09
> > 8-5-9
> > 8 05 2009
> > 8,5,9
> > 
> > Or any combination thereof.
> > 
> > However, the resultant date will be standardized to: Aug 5, 2009.
> > 
> > Extra points for solving this for Euro as well as US date formats (i.e., 
> > 5 Aug, 2009 vs Aug 5, 2009).  And, extra extra points for accommodating 
> > month brevity, such as "A" for August and "Mar" for March and so on.
> 
> But the real problem here is 05/08/09 is still August 5 2009 .
> So teaching customers to use 2009.08.05 removes the hassle of needing to know 
> where your target site is based!
> 
> But as has been said, the real solution is a date picker.
> 
> -- 
> Lester Caine - G8HFL
> -
> Contact - http://lsces.co.uk/wiki/?page=contact
> L.S.Caine Electronic Services - http://lsces.co.uk
> EnquirySolve - http://enquirysolve.com/
> Model Engineers Digital Workshop - http://medw.co.uk//
> Firebird - http://www.firebirdsql.org/index.php
> 

Seriously, go out and beat your clients over the head, and then hit them
about some more until they understand the folly of using bad date
formats. US-style dates are just the start of it!

Thanks,
Ash
http://www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Another date exercise

2009-08-16 Thread Lester Caine

tedd wrote:

Hi gang:

Here's another exercise to consider.

This is a date entry problem where the user can enter a date in various 
forms, but the return will be in a consistent format.


For example, a user might enter a date in the form of:

August 5, 2009
Aug 05 2009
Aug 5, 9
08/05/09
8-5-9
8 05 2009
8,5,9

Or any combination thereof.

However, the resultant date will be standardized to: Aug 5, 2009.

Extra points for solving this for Euro as well as US date formats (i.e., 
5 Aug, 2009 vs Aug 5, 2009).  And, extra extra points for accommodating 
month brevity, such as "A" for August and "Mar" for March and so on.


But the real problem here is 05/08/09 is still August 5 2009 .
So teaching customers to use 2009.08.05 removes the hassle of needing to know 
where your target site is based!


But as has been said, the real solution is a date picker.

--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Another date exercise

2009-08-15 Thread Phpster


On Aug 15, 2009, at 3:57 PM, tedd  wrote:


Hi gang:

Here's another exercise to consider.

This is a date entry problem where the user can enter a date in  
various forms, but the return will be in a consistent format.


For example, a user might enter a date in the form of:

August 5, 2009
Aug 05 2009
Aug 5, 9
08/05/09
8-5-9
8 05 2009
8,5,9

Or any combination thereof.

However, the resultant date will be standardized to: Aug 5, 2009.

Extra points for solving this for Euro as well as US date formats  
(i.e., 5 Aug, 2009 vs Aug 5, 2009).  And, extra extra points for  
accommodating month brevity, such as "A" for August and "Mar" for  
March and so on.


Gentlemen, start your keyboards.  :-)

As always, should you or any of your IM Force be caught or killed,  
The Secretary will disavow any knowledge of your actions.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Use a js date picker and avoid the whole issue.

Bastien

Sent from my iPod
 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php