Persian day names are different than English, and also week starts Saturday. So I have this weekday name and number conversion function:
function getDayNames($day, $shorten = false, $len = 1, $numeric = false)
{
$ret = '';
switch ( strtolower($day) ) {
case 'sat': case 'saturday': $ret = 'شنبه'; $n = 1; break;
case 'sun': case 'sunday': $ret = 'یکشنبه'; $n = 2; break;
case 'mon': case 'monday': $ret = 'دوشنبه'; $n = 3; break;
case 'tue': case 'tuesday': $ret = 'سه شنبه'; $n = 4; break;
case 'wed': case 'wednesday': $ret = 'چهارشنبه'; $n = 5; break;
case 'thu': case 'thursday': $ret = 'پنجشنبه'; $n = 6; break;
case 'fri': case 'friday': $ret = 'جمعه'; $n = 7; break;
}
return ($numeric) ? $n : (($shorten) ? substr($ret, 0, $len) : $ret);
}
and I wanna know if there is a better way to rewrite this. Using switch
is not ideal.
Thanks in advance.
Possibly arrayify it: