/*
To facilitate the creation of examples, this function will
generate a valid randomized calendar date for the selected
calendar mode within the given year span.
BC years are entered as negative values.
There is no calendar year 0 (zero).
DEPENDENCIES:
Is_Valid_Date()
Num_Date_to_Full_Date()
*/
function Random_Date_Str ($sYMin=1900, $sYMax=2100, $JorG='G', $RetMode=1)
{
$sYMin = trim($sYMin);
$sYMax = trim($sYMax);
// Error if either year argument is non-numeric.
if (!Is_Numeric($sYMin) or !Is_Numeric($sYMax)) {return FALSE;}
$ValidDate = FALSE;
while ($ValidDate === FALSE)
{
$RsY = Random_Int($sYMin, $sYMax);
$AbsRsY = SPrintF("%05d", abs($RsY));
$RsY = ($RsY < 0)? "-$AbsRsY" : $AbsRsY;
$Rmm = SPrintF("%02d", Random_Int(1, 12));
$Rdd = SPrintF("%02d", Random_Int(1, 31));
$RsYmmdd = "$RsY/$Rmm/$Rdd";
$ValidDate = Is_Valid_Date ($RsYmmdd, $JorG);
}
if ($RetMode == 2) {return Num_Date_to_Full_Date ($RsYmmdd, $JorG);}
return $RsYmmdd;
}