Totally Zenned
- Join Date:
- Jan 2005
- Posts:
- 1,285
- Plugin Contributions:
- 0
Post #1 by dwno
Hi,
I made some improvements to the function zen_date_raw().
You should now be able to enter your birthday in several ways, based on what the constant DATE_FORMAT is set to. For example, you can insert 270282, 27282, 2721982, 27021982, 27 lhabfdkj /&%¤" 02 -82, 1182 (which becomes 01011982), 11182 (which becomes 11011982), 27.02.82, 27/02-1982, etc.
Some of those will probably never be used, but the best part IMO is that you don't have to separate the date with slashes anymore.
There should also be made changes to some javascript somewhere, so you only need to insert YY instead of YYYY, but I haven't looked at that yet.
DATE_FORMAT can be set to any combination of dmY except dYm or mYd. (Those aren't used anywhere, are they?) Casing doesn't matter, and any other characters, such as slash or dash, don't matter either.
function zen_date_raw($date, $reverse = false) {
$date = ereg_replace("[^0-9]","", $date);
$dformat=DATE_FORMAT;
$dformat = ereg_replace("[^dmy]","", $dformat);
$dd="([0-2][1-9]|[1-3][0-1]|[1-9])";
$mm="(0?[1-9]|1[0-2])";
$yyyy="((19|20)?[0-9]{2})";
if (strtolower($dformat)=="dmy") {$regexp=$dd . $mm . $yyyy; $d="2"; $m="3"; $y="4";}
else if (strtolower($dformat)=="mdy") {$regexp=$mm . $dd . $yyyy; $d="3"; $m="2"; $y="4";}
else if (strtolower($dformat)=="ydm") {$regexp=$yyyy . $dd . $mm; $d="4"; $m="5"; $y="2";}
else if (strtolower($dformat)=="ymd") {$regexp=$yyyy . $mm . $dd; $d="5"; $m="4"; $y="2";}
ereg("(^" . $regexp . "$)", $date, $regs);
// fix value of day
if (strlen($regs[$d])=="1") {$regs[$d]="0" . $regs[$d];}
// fix value of month
if (strlen($regs[$m])=="1") {$regs[$m]="0" . $regs[$m];}
// fix value of year
if (strlen($regs[$y])=="2") {$regs[$y]="19" . $regs[$y];}
if ($reverse) {
$date=$regs[$d] . $regs[$m] . $regs[$y];
return $date;
} else {
$date=$regs[$y] . $regs[$m] . $regs[$d];
return $date;
}
}
One thing I'm not entirely sure of; $reverse should return ddmmyyyy, and not vice-versa, right?
So what do you think?
And let me know if you want additional comments inside the function.