From: Joe Hunt Date: Tue, 2 Oct 2012 20:50:32 +0000 (+0200) Subject: 0001806: Date problems fixed and new date formats MmmDDYYYY, DDMmmYYYY and YYYYMmmDD... X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=9f6512b59438dda856314cec6c1bbcee6ac41581;p=textcart.git 0001806: Date problems fixed and new date formats MmmDDYYYY, DDMmmYYYY and YYYYMmmDD implemented. --- diff --git a/admin/display_prefs.php b/admin/display_prefs.php index 4c90ec7..8768c57 100644 --- a/admin/display_prefs.php +++ b/admin/display_prefs.php @@ -33,6 +33,8 @@ if (isset($_POST['setprefs'])) $_POST['theme'] = clean_file_name($_POST['theme']); $chg_theme = user_theme() != $_POST['theme']; $chg_lang = $_SESSION['language']->code != $_POST['language']; + $chg_date_format = user_date_format() != $_POST['date_format']; + $chg_date_sep = user_date_sep() != $_POST['date_sep']; set_user_prefs(get_post( array('prices_dec', 'qty_dec', 'rates_dec', 'percent_dec', @@ -50,8 +52,7 @@ if (isset($_POST['setprefs'])) if ($chg_theme && $allow_demo_mode) $_SESSION["wa_current_user"]->prefs->theme = $_POST['theme']; - - if ($chg_theme || $chg_lang) + if ($chg_theme || $chg_lang || $chg_date_format || $chg_date_sep) meta_forward($_SERVER['PHP_SELF']); diff --git a/config.default.php b/config.default.php index 1786366..43c2547 100644 --- a/config.default.php +++ b/config.default.php @@ -136,7 +136,7 @@ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_ /* suppress tax rates on documents. 0 = no, 1 = yes. */ $suppress_tax_rates = 0; - $dateformats = array("MMDDYYYY", "DDMMYYYY", "YYYYMMDD"); + $dateformats = array("MMDDYYYY", "DDMMYYYY", "YYYYMMDD","MmmDDYYYY", "DDMmmYYYY", "YYYYMmmDD"); $dateseps = array("/", ".", "-", " "); $thoseps = array(",", ".", " "); $decseps = array(".", ","); @@ -144,6 +144,9 @@ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_ $dflt_date_fmt = 0; $dflt_date_sep = 0; + /* This month array is for use with the last 3 dateformats. */ + $tmonths = array("", _("Jan"),_("Feb"),_("Mar"),_("Apr"),_("May"),_("Jun"),_("Jul"),_("Aug"),_("Sep"),_("Oct"),_("Nov"),_("Dec")); + $pagesizes = array("Letter", "A4"); // default PDF pagesize /* Accounts Payable */ diff --git a/includes/date_functions.inc b/includes/date_functions.inc index 6f8379e..4a89755 100644 --- a/includes/date_functions.inc +++ b/includes/date_functions.inc @@ -21,22 +21,31 @@ this can be a string either "d/m/Y" for UK/Australia/New Zealand dates or function __date($year, $month, $day) { - global $dateseps; + global $dateseps, $tmonths; $how = user_date_format(); $sep = $dateseps[user_date_sep()]; $day = (int)$day; $month = (int)$month; - if ($day < 10) - $day = "0".$day; - if ($month < 10) - $month = "0".$month; + if ($how < 3) + { + if ($day < 10) + $day = "0".$day; + if ($month < 10) + $month = "0".$month; + } if ($how == 0) return $month.$sep.$day.$sep.$year; elseif ($how == 1) return $day.$sep.$month.$sep.$year; - else + elseif ($how == 2) return $year.$sep.$month.$sep.$day; + elseif ($how == 3) + return $tmonths[$month].$sep.$day.$sep.$year; + elseif ($how == 4) + return $day.$sep.$tmonths[$month].$sep.$year; + else + return $year.$sep.$tmonths[$month].$sep.$day; } function is_date($date_) @@ -49,55 +58,79 @@ function is_date($date_) $sep = $dateseps[user_date_sep()]; $date_ = trim($date_); - $date_ = str_replace($sep, "", $date_); + $date = str_replace($sep, "", $date_); if (strlen($date_) == 6) { if ($how == 0) { - $day = substr($date_,2,2); - $month = substr($date_,0,2); - $year = substr($date_,4,2); + $day = substr($date,2,2); + $month = substr($date,0,2); + $year = substr($date,4,2); } elseif ($how == 1) { - $day = substr($date_,0,2); - $month = substr($date_,2,2); - $year = substr($date_,4,2); + $day = substr($date,0,2); + $month = substr($date,2,2); + $year = substr($date,4,2); } else { - $day = substr($date_,4,2); - $month = substr($date_,2,2); - $year = substr($date_,0,2); + $day = substr($date,4,2); + $month = substr($date,2,2); + $year = substr($date,0,2); } } elseif (strlen($date_) == 8) { if ($how == 0) { - $day = substr($date_,2,2); - $month = substr($date_,0,2); - $year = substr($date_,4,4); + $day = substr($date,2,2); + $month = substr($date,0,2); + $year = substr($date,4,4); } elseif ($how == 1) { - $day = substr($date_,0,2); - $month = substr($date_,2,2); - $year = substr($date_,4,4); + $day = substr($date,0,2); + $month = substr($date,2,2); + $year = substr($date,4,4); } else { - $day = substr($date_,6,2); - $month = substr($date_,4,2); - $year = substr($date_,0,4); + $day = substr($date,6,2); + $month = substr($date,4,2); + $year = substr($date,0,4); } } + elseif ($how > 2) + { + global $tmonths; + $dd = explode($sep, $date_); + if ($how == 3) + { + $day = $dd[1]; + $month = array_search($dd[0], $tmonths); + $year = $dd[2]; + } + elseif ($how == 4) + { + $day = $dd[0]; + $month = array_search($dd[1], $tmonths); + $year = $dd[2]; + } + else + { + $day = $dd[2]; + $month = array_search($dd[1], $tmonths); + $year = $dd[0]; + } + if ($year < 1000) + return 0; + } if (!isset($year)|| (int)$year > 9999) { return 0; } - if (is_long((int)$day) && is_long((int)$month) && is_long((int)$year)) { global $date_system; @@ -333,7 +366,7 @@ function sql2date($date_) function date2sql($date_) { - global $dateseps, $date_system; + global $dateseps, $date_system, $tmonths; /* takes a date in a the format specified in $DefaultDateFormat and converts to a yyyy/mm/dd format */ @@ -345,15 +378,18 @@ and converts to a yyyy/mm/dd format */ $date_ = trim($date_); $year = $month = $day = 0; - // Split up the date by the separator based on "how" to split it - if ($how == 0) // MMDDYYYY + if ($how == 0 || $how == 3) // MMDDYYYY or MmmDDYYYY list($month, $day, $year) = explode($sep, $date_); - elseif ($how == 1) // DDMMYYYY + elseif ($how == 1 || $how == 4) // DDMMYYYY or DDMmYYYY list($day, $month, $year) = explode($sep, $date_); - else // $how == 2, YYYYMMDD + else // $how == 2 || $how == 5, YYYYMMDD or YYYYMmmDD list($year, $month, $day) = explode($sep, $date_); - + if ($how > 2) + { + global $tmonths; + $month = array_search($month, $tmonths); + } //to modify assumption in 2030 if ($date_system == 0 || $date_system == 3) { diff --git a/includes/prefs/userprefs.inc b/includes/prefs/userprefs.inc index 50fa0a8..811e663 100644 --- a/includes/prefs/userprefs.inc +++ b/includes/prefs/userprefs.inc @@ -163,8 +163,14 @@ class user_prefs return "m".$sep."d".$sep."Y"; elseif ($this->date_format == 1) return "d".$sep."m".$sep."Y"; - else + elseif ($this->date_format == 2) return "Y".$sep."m".$sep."d"; + elseif ($this->date_format == 3) + return "M".$sep."j".$sep."Y"; + elseif ($this->date_format == 4) + return "j".$sep."M".$sep."Y"; + else + return "Y".$sep."M".$sep."j"; } function tho_sep() diff --git a/includes/ui/ui_input.inc b/includes/ui/ui_input.inc index 7929d07..9ae512b 100644 --- a/includes/ui/ui_input.inc +++ b/includes/ui/ui_input.inc @@ -645,7 +645,8 @@ function date_cells($label, $name, $title = null, $check=null, $inc_days=0, $aspect .= ' style="color:#FF0000"'; default_focus($name); - echo "3)?11:10; + echo " $post_label"; echo "\n"; diff --git a/includes/ui/ui_view.inc b/includes/ui/ui_view.inc index e8991c8..616a0ff 100644 --- a/includes/ui/ui_view.inc +++ b/includes/ui/ui_view.inc @@ -833,11 +833,11 @@ function get_js_date_picker() if (!file_exists($fpath) || $go_debug) { - global $dateseps, $date_system; + global $dateseps, $date_system, $tmonths; $how = user_date_format(); // 0 = us/ca, 1 = eu, au, nz, 2 = jp, sw $sep = $dateseps[user_date_sep()]; // date separator - $wstart = (($date_system == 1 || $date_system == 2 || $date_system == 3) ? 6 : ($how == 0 ? 0 : 1)); // weekstart (sun = 0, mon = 1) + $wstart = (($date_system == 1 || $date_system == 2 || $date_system == 3) ? 6 : ($how == 0 || $how == 3 ? 0 : 1)); // weekstart (sun = 0, mon = 1) $months = array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December")); $wdays = array(_("Su"),_("Mo"),_("Tu"),_("We"),_("Th"),_("Fr"),_("Sa")); $wno = _("W"); // week no @@ -920,6 +920,7 @@ function CC() { var selectedDay = 0; var months = ['$months[0]','$months[1]','$months[2]','$months[3]','$months[4]','$months[5]','$months[6]','$months[7]','$months[8]','$months[9]','$months[10]','$months[11]']; var wdays = ['$wdays[0]', '$wdays[1]', '$wdays[2]', '$wdays[3]', '$wdays[4]', '$wdays[5]', '$wdays[6]']; + var tmonths = ['$tmonths[0]','$tmonths[1]','$tmonths[2]','$tmonths[3]','$tmonths[4]','$tmonths[5]','$tmonths[6]','$tmonths[7]','$tmonths[8]','$tmonths[9]','$tmonths[10]','$tmonths[11]','$tmonths[12]']; var dateField = null; function getProperty(p_property){ var p_elm = calendarId; @@ -1022,7 +1023,7 @@ function CC() { this.getWeek = getWeek; function getWeek(year, month, day) { "; - if ($how == 0) + if ($how == 0 || $how == 3) $js .= " day++;"; $js .= " var date = new Date(year,month-1,day); @@ -1036,19 +1037,26 @@ function CC() { } this.setDate = setDate; function setDate(year, month, day) { - if (dateField) { + if (dateField){ +"; + if ($how < 3) + $js .= " if (month < 10) {month = '0' + month;} if (day < 10) {day = '0' + day;} "; - if ($how == 0) + else + $js .= " + month = tmonths[month]; +"; + if ($how == 0 || $how == 3) $js .= " var dateString = month+'$sep'+day+'$sep'+year; "; - else if ($how == 1) + else if ($how == 1 || $how == 4) $js .= " var dateString = day+'$sep'+month+'$sep'+year; "; - else + else if ($how == 2 || $how == 5) $js .= " var dateString = year+'$sep'+month+'$sep'+day; "; @@ -1184,11 +1192,29 @@ function CC() { selectedMonth = parseInt(dateParts[1],10); selectedYear = parseInt(dateParts[2],10); "; - else + else if ($how == 2) $js .= " selectedYear = parseInt(dateParts[0],10); selectedMonth = parseInt(dateParts[1],10); selectedDay = parseInt(dateParts[2],10); +"; + else if ($how == 3) + $js .= " + selectedDay = parseInt(dateParts[1],10); + selectedMonth = parseInt(tmonths.indexOf(dateParts[0]),10); + selectedYear = parseInt(dateParts[2],10); +"; + else if ($how == 4) + $js .= " + selectedDay = parseInt(dateParts[0],10); + selectedMonth = parseInt(tmonths.indexOf(dateParts[1]),10); + selectedYear = parseInt(dateParts[2],10); +"; + else + $js .= " + selectedYear = parseInt(dateParts[0],10); + selectedMonth = parseInt(tmonths.indexOf(dateParts[1]),10); + selectedDay = parseInt(dateParts[2],10); "; $js .= " } catch(e) {} diff --git a/js/inserts.js b/js/inserts.js index 2e706fb..a22238b 100644 --- a/js/inserts.js +++ b/js/inserts.js @@ -213,47 +213,40 @@ function passBack(value) { */ function fix_date(date, last) { - var regex = /(\d+)[^\d]*(\d+)*[^\d]*(\d+)*/; - var dat = regex.exec(last); - var cur = regex.exec(date); + var dat = last.split(user.datesep); + var cur = date.split(user.datesep); var day, month, year; + var day1, month1, year1; // TODO: user.date as default? // TODO: user.datesys - if (!dat || !cur) return date; - - if (cur[3] != undefined) // full date entered - dat = cur; - - if (user.datefmt == 0) // set defaults + if (date == "" || date == last) // should we return an empty date or should we return last? + return date; + if (user.datefmt == 0 || user.datefmt == 3) // set defaults { - day = dat[2]; month = dat[1]; year = dat[3]; - } else if (user.datefmt == 1) - { - day = dat[1]; month = dat[2]; year = dat[3]; + day = dat[1]; month = dat[0]; year = dat[2]; + day1 = cur[1]; month1 = cur[0]; year1 = cur[2]; + } else if (user.datefmt == 1 || user.datefmt == 4){ + day = dat[0]; month = dat[1]; year = dat[2]; + day1 = cur[0]; month1 = cur[1]; year1 = cur[2]; } else { - day = dat[3]; month = dat[2]; year = dat[1]; - } - - if (cur[2] == undefined) // only day entred - day = cur[1]; - else // day + month - if (cur[2] != undefined) - { - if (user.datefmt==1) - { day = cur[1]; month = cur[2] } - else - { day = cur[2]; month = cur[1] } - } - - if (day<10) day = '0'+parseInt(day, 10); - if (month<10) month = '0'+parseInt(month, 10); + day = dat[2]; month = dat[1]; year = dat[0]; + day1 = cur[2]; month1 = cur[1]; year1 = cur[0]; + } + if (day1 != undefined && day1 != "") // day entered + day = day1; + if (month1 != undefined && month1 != "") // month entered + month = month1; + if (year1 != undefined && year1 != "") // year entered + year = year1; + if (user.datefmt<3 && day<10) day = '0'+parseInt(day, 10); + if (user.datefmt<3 && month<10) month = '0'+parseInt(month, 10); if (year<100) year = year<60 ? (2000+parseInt(year,10)) : (1900+parseInt(year,10)); // console.info(day,month,year) - if (user.datefmt == 0) + if (user.datefmt == 0 || user.datefmt==3) return month+user.datesep+day+user.datesep+year; - if (user.datefmt == 1) + if (user.datefmt == 1 || user.datefmt==4) return day+user.datesep+month+user.datesep+year; return year+user.datesep+month+user.datesep+day; }