function adodb_gmstrftime($fmt, $ts = false) { return adodb_strftime($fmt, $ts, true); }
/** * Convert (by PHP) a GM Timestamp date into a GM string date to insert into a date field. * Function to use to build INSERT, UPDATE or WHERE predica * @param param Date TMS to convert * @return string Date in a string YYYYMMDDHHMMSS */ function idate($param) { return adodb_strftime("%Y-%m-%d %H:%M:%S", $param); }
public function format($strf) { return utf8_encode(adodb_strftime($strf, $this->ts())); }
/** * Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field. * Function to use to build INSERT, UPDATE or WHERE predica * @param param Date TMS to convert * @return string Date in a string YYYYMMDDHHMMSS */ function idate($param) { return adodb_strftime("%Y%m%d%H%M%S", $param); }
/** * Output date in a string format according to outputlangs (or langs if not defined). * Return charset is always UTF-8, except if encodetoouput is defined. In this cas charset is output charset. * @param time GM Timestamps date (or deprecated strings 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS') * @param format Output date format * "%d %b %Y", * "%d/%m/%Y %H:%M", * "%d/%m/%Y %H:%M:%S", * "day", "daytext", "dayhour", "dayhourldap", "dayhourtext" * @param tzoutput true=output or 'gmt' => string is for Greenwich location * false or 'tzserver' => output string is for local PHP server TZ usage * 'tzuser' => output string is for local browser TZ usage * @param outputlangs Object lang that contains language for text translation. * @param encodetooutput false=no convert into output pagecode * @return string Formated date or '' if time is null * @see dol_mktime, dol_stringtotime, dol_getdate */ function dol_print_date($time, $format = '', $tzoutput = 'tzserver', $outputlangs = '', $encodetooutput = false) { global $conf, $langs; $to_gmt = false; $offsettz = $offsetdst = 0; if ($tzoutput) { $to_gmt = true; // For backward compatibility if (is_string($tzoutput)) { if ($tzoutput == 'tzserver') { $to_gmt = false; $offsettz = $offsetdst = 0; } if ($tzoutput == 'tzuser') { $to_gmt = true; $offsettz = (empty($_SESSION['dol_tz']) ? 0 : $_SESSION['dol_tz']) * 60 * 60; $offsetdst = (empty($_SESSION['dol_dst']) ? 0 : $_SESSION['dol_dst']) * 60 * 60; } if ($tzoutput == 'tzcompany') { $to_gmt = false; $offsettz = $offsetdst = 0; // TODO Define this and use it later } } } if (!is_object($outputlangs)) { $outputlangs = $langs; } // Si format non defini, on prend $conf->format_date_text_short sinon %Y-%m-%d %H:%M:%S if (!$format) { $format = isset($conf->format_date_text_short) ? $conf->format_date_text_short : '%Y-%m-%d %H:%M:%S'; } // Change predefined format into computer format. If found translation in lang file we use it, otherwise we use default. if ($format == 'day') { $format = $outputlangs->trans("FormatDateShort") != "FormatDateShort" ? $outputlangs->trans("FormatDateShort") : $conf->format_date_short; } if ($format == 'hour') { $format = $outputlangs->trans("FormatHourShort") != "FormatHourShort" ? $outputlangs->trans("FormatHourShort") : $conf->format_hour_short; } if ($format == 'hourduration') { $format = $outputlangs->trans("FormatHourShortDuration") != "FormatHourShortDuration" ? $outputlangs->trans("FormatHourShortDuration") : $conf->format_hour_short_duration; } if ($format == 'daytext') { $format = $outputlangs->trans("FormatDateText") != "FormatDateText" ? $outputlangs->trans("FormatDateText") : $conf->format_date_text; } if ($format == 'daytextshort') { $format = $outputlangs->trans("FormatDateTextShort") != "FormatDateTextShort" ? $outputlangs->trans("FormatDateTextShort") : $conf->format_date_text_short; } if ($format == 'dayhour') { $format = $outputlangs->trans("FormatDateHourShort") != "FormatDateHourShort" ? $outputlangs->trans("FormatDateHourShort") : $conf->format_date_hour_short; } if ($format == 'dayhourtext') { $format = $outputlangs->trans("FormatDateHourText") != "FormatDateHourText" ? $outputlangs->trans("FormatDateHourText") : $conf->format_date_hour_text; } if ($format == 'dayhourtextshort') { $format = $outputlangs->trans("FormatDateHourTextShort") != "FormatDateHourTextShort" ? $outputlangs->trans("FormatDateHourTextShort") : $conf->format_date_hour_text_short; } // Format not sensitive to language if ($format == 'dayhourlog') { $format = '%Y%m%d%H%M%S'; } if ($format == 'dayhourldap') { $format = '%Y%m%d%H%M%SZ'; } if ($format == 'dayhourxcard') { $format = '%Y%m%dT%H%M%SZ'; } if ($format == 'dayxcard') { $format = '%Y%m%d'; } if ($format == 'dayrfc') { $format = '%Y-%m-%d'; } // DATE_RFC3339 if ($format == 'dayhourrfc') { $format = '%Y-%m-%dT%H:%M:%SZ'; } // DATETIME RFC3339 // If date undefined or "", we return "" if (dol_strlen($time) == 0) { return ''; } // $time=0 allowed (it means 01/01/1970 00:00:00) //print 'x'.$time; if (preg_match('/%b/i', $format)) { // We inhibate translation to text made by strftime functions. We will use trans instead later. $format = str_replace('%b', '__b__', $format); $format = str_replace('%B', '__B__', $format); } if (preg_match('/%a/i', $format)) { // We inhibate translation to text made by strftime functions. We will use trans instead later. $format = str_replace('%a', '__a__', $format); $format = str_replace('%A', '__A__', $format); } // Analyze date (deprecated) Ex: 1970-01-01, 1970-01-01 01:00:00, 19700101010000 if (preg_match('/^([0-9]+)\\-([0-9]+)\\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $time, $reg) || preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/i', $time, $reg)) { // This part of code should not be used. dol_syslog("Functions.lib::dol_print_date function call with deprecated value of time in page " . $_SERVER["PHP_SELF"], LOG_WARNING); // Date has format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS' or 'YYYYMMDDHHMMSS' $syear = $reg[1]; $smonth = $reg[2]; $sday = $reg[3]; $shour = $reg[4]; $smin = $reg[5]; $ssec = $reg[6]; $time = dol_mktime($shour, $smin, $ssec, $smonth, $sday, $syear, true); $ret = adodb_strftime($format, $time + $offsettz + $offsetdst, $to_gmt); } else { // Date is a timestamps if ($time < 100000000000) { $ret = adodb_strftime($format, $time + $offsettz + $offsetdst, $to_gmt); } else { $ret = 'Bad value ' . $time . ' for date'; } } if (preg_match('/__b__/i', $format)) { // Here ret is string in PHP setup language (strftime was used). Now we convert to $outputlangs. $month = adodb_strftime('%m', $time + $offsettz + $offsetdst); if ($encodetooutput) { $monthtext = $outputlangs->transnoentities('Month' . $month); $monthtextshort = $outputlangs->transnoentities('MonthShort' . $month); } else { $monthtext = $outputlangs->transnoentitiesnoconv('Month' . $month); $monthtextshort = $outputlangs->transnoentitiesnoconv('MonthShort' . $month); } //print 'monthtext='.$monthtext.' monthtextshort='.$monthtextshort; $ret = str_replace('__b__', $monthtextshort, $ret); $ret = str_replace('__B__', $monthtext, $ret); //print 'x'.$outputlangs->charset_output.'-'.$ret.'x'; //return $ret; } if (preg_match('/__a__/i', $format)) { $w = adodb_strftime('%w', $time + $offsettz + $offsetdst); $dayweek = $outputlangs->transnoentitiesnoconv('Day' . $w); $ret = str_replace('__A__', $dayweek, $ret); $ret = str_replace('__a__', dol_substr($dayweek, 0, 3), $ret); } return $ret; }
function timeToStr($int) { global $pommo; if (!defined('ADODB_DATE_VERSION')) { // safely load ADODB date library Pommo::requireOnce($pommo->_baseDir . 'inc/lib/adodb/adodb-time.inc.php'); } switch ($pommo->_dateformat) { case 1: $format = '%Y/%m/%d'; break; case 2: $format = '%m/%d/%Y'; break; case 3: $format = '%d/%m/%Y'; break; default: Pommo::kill('Unknown dateformat', TRUE); } return adodb_strftime($format, $int); }
/** * Alias for adodb_strftime() */ function carl_strftime($format, $timestamp = false, $is_gmt = false) { return adodb_strftime($format, $timestamp, $is_gmt); }
/** * Output date in a string format according to outputlangs (or langs if not defined). * Return charset is always UTF-8, except if encodetoouput is defined. In this case charset is output charset * * @param int $time GM Timestamps date * @param string $format Output date format (tag of strftime function) * "%d %b %Y", * "%d/%m/%Y %H:%M", * "%d/%m/%Y %H:%M:%S", * "day", "daytext", "dayhour", "dayhourldap", "dayhourtext", "dayrfc", "dayhourrfc" * @param string $tzoutput true or 'gmt' => string is for Greenwich location * false or 'tzserver' => output string is for local PHP server TZ usage * 'tzuser' => output string is for user TZ (current browser TZ with current dst) * 'tzuserrel' => output string is for user TZ (current browser TZ with dst or not, depending on date position) * @param Translate $outputlangs Object lang that contains language for text translation. * @param boolean $encodetooutput false=no convert into output pagecode * @return string Formated date or '' if time is null * * @see dol_mktime, dol_stringtotime, dol_getdate */ function dol_print_date($time, $format = '', $tzoutput = 'tzserver', $outputlangs = '', $encodetooutput = false) { global $conf, $langs; // Clean parameters $to_gmt = false; $offsettz = $offsetdst = 0; if ($tzoutput) { $to_gmt = true; // For backward compatibility if (is_string($tzoutput)) { if ($tzoutput == 'tzserver') { $to_gmt = false; $offsettzstring = @date_default_timezone_get(); // Example 'Europe/Berlin' or 'Indian/Reunion' $offsettz = 0; $offsetdst = 0; } elseif ($tzoutput == 'tzuser') { $to_gmt = true; $offsettzstring = empty($_SESSION['dol_tz_string']) ? 'UTC' : $_SESSION['dol_tz_string']; // Example 'Europe/Berlin' or 'Indian/Reunion' $offsettz = (empty($_SESSION['dol_tz']) ? 0 : $_SESSION['dol_tz']) * 60 * 60; $offsetdst = (empty($_SESSION['dol_dst']) ? 0 : $_SESSION['dol_dst']) * 60 * 60; } } } if (!is_object($outputlangs)) { $outputlangs = $langs; } if (!$format) { $format = 'daytextshort'; } $reduceformat = !empty($conf->dol_optimize_smallscreen) && in_array($format, array('day', 'dayhour')) ? 1 : 0; $formatwithoutreduce = preg_replace('/reduceformat/', '', $format); if ($formatwithoutreduce != $format) { $format = $formatwithoutreduce; $reduceformat = 1; } // so format 'dayreduceformat' is processed like day // Change predefined format into computer format. If found translation in lang file we use it, otherwise we use default. if ($format == 'day') { $format = $outputlangs->trans("FormatDateShort") != "FormatDateShort" ? $outputlangs->trans("FormatDateShort") : $conf->format_date_short; } else { if ($format == 'hour') { $format = $outputlangs->trans("FormatHourShort") != "FormatHourShort" ? $outputlangs->trans("FormatHourShort") : $conf->format_hour_short; } else { if ($format == 'hourduration') { $format = $outputlangs->trans("FormatHourShortDuration") != "FormatHourShortDuration" ? $outputlangs->trans("FormatHourShortDuration") : $conf->format_hour_short_duration; } else { if ($format == 'daytext') { $format = $outputlangs->trans("FormatDateText") != "FormatDateText" ? $outputlangs->trans("FormatDateText") : $conf->format_date_text; } else { if ($format == 'daytextshort') { $format = $outputlangs->trans("FormatDateTextShort") != "FormatDateTextShort" ? $outputlangs->trans("FormatDateTextShort") : $conf->format_date_text_short; } else { if ($format == 'dayhour') { $format = $outputlangs->trans("FormatDateHourShort") != "FormatDateHourShort" ? $outputlangs->trans("FormatDateHourShort") : $conf->format_date_hour_short; } else { if ($format == 'dayhoursec') { $format = $outputlangs->trans("FormatDateHourSecShort") != "FormatDateHourSecShort" ? $outputlangs->trans("FormatDateHourSecShort") : $conf->format_date_hour_sec_short; } else { if ($format == 'dayhourtext') { $format = $outputlangs->trans("FormatDateHourText") != "FormatDateHourText" ? $outputlangs->trans("FormatDateHourText") : $conf->format_date_hour_text; } else { if ($format == 'dayhourtextshort') { $format = $outputlangs->trans("FormatDateHourTextShort") != "FormatDateHourTextShort" ? $outputlangs->trans("FormatDateHourTextShort") : $conf->format_date_hour_text_short; } else { if ($format == 'dayhourlog') { $format = '%Y%m%d%H%M%S'; } else { if ($format == 'dayhourldap') { $format = '%Y%m%d%H%M%SZ'; } else { if ($format == 'dayhourxcard') { $format = '%Y%m%dT%H%M%SZ'; } else { if ($format == 'dayxcard') { $format = '%Y%m%d'; } else { if ($format == 'dayrfc') { $format = '%Y-%m-%d'; } else { if ($format == 'dayhourrfc') { $format = '%Y-%m-%dT%H:%M:%SZ'; } else { if ($format == 'standard') { $format = '%Y-%m-%d %H:%M:%S'; } } } } } } } } } } } } } } } } if ($reduceformat) { $format = str_replace('%Y', '%y', $format); $format = str_replace('yyyy', 'yy', $format); } // If date undefined or "", we return "" if (dol_strlen($time) == 0) { return ''; } // $time=0 allowed (it means 01/01/1970 00:00:00) // Clean format if (preg_match('/%b/i', $format)) { // We inhibate translation to text made by strftime functions. We will use trans instead later. $format = str_replace('%b', '__b__', $format); $format = str_replace('%B', '__B__', $format); } if (preg_match('/%a/i', $format)) { // We inhibate translation to text made by strftime functions. We will use trans instead later. $format = str_replace('%a', '__a__', $format); $format = str_replace('%A', '__A__', $format); } // Analyze date if (preg_match('/^([0-9]+)\\-([0-9]+)\\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $time, $reg) || preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/i', $time, $reg)) { // This part of code should not be used. TODO Remove this. dol_syslog("Functions.lib::dol_print_date function call with deprecated value of time in page " . $_SERVER["PHP_SELF"], LOG_WARNING); // Date has format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS' or 'YYYYMMDDHHMMSS' $syear = !empty($reg[1]) ? $reg[1] : ''; $smonth = !empty($reg[2]) ? $reg[2] : ''; $sday = !empty($reg[3]) ? $reg[3] : ''; $shour = !empty($reg[4]) ? $reg[4] : ''; $smin = !empty($reg[5]) ? $reg[5] : ''; $ssec = !empty($reg[6]) ? $reg[6] : ''; $time = dol_mktime($shour, $smin, $ssec, $smonth, $sday, $syear, true); $ret = adodb_strftime($format, $time + $offsettz + $offsetdst, $to_gmt); } else { // Date is a timestamps if ($time < 100000000000) { $ret = adodb_strftime($format, $time + $offsettz + $offsetdst, $to_gmt); // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring. } else { $ret = 'Bad value ' . $time . ' for date'; } } if (preg_match('/__b__/i', $format)) { // Here ret is string in PHP setup language (strftime was used). Now we convert to $outputlangs. $month = adodb_strftime('%m', $time + $offsettz + $offsetdst); // TODO Remove this if ($encodetooutput) { $monthtext = $outputlangs->transnoentities('Month' . $month); $monthtextshort = $outputlangs->transnoentities('MonthShort' . $month); } else { $monthtext = $outputlangs->transnoentitiesnoconv('Month' . $month); $monthtextshort = $outputlangs->transnoentitiesnoconv('MonthShort' . $month); } //print 'monthtext='.$monthtext.' monthtextshort='.$monthtextshort; $ret = str_replace('__b__', $monthtextshort, $ret); $ret = str_replace('__B__', $monthtext, $ret); //print 'x'.$outputlangs->charset_output.'-'.$ret.'x'; //return $ret; } if (preg_match('/__a__/i', $format)) { $w = adodb_strftime('%w', $time + $offsettz + $offsetdst); // TODO Remove this $dayweek = $outputlangs->transnoentitiesnoconv('Day' . $w); $ret = str_replace('__A__', $dayweek, $ret); $ret = str_replace('__a__', dol_substr($dayweek, 0, 3), $ret); } return $ret; }