public function __toString() { return "Class A object"; } } class classWithoutToString { } // heredoc string $heredoc = <<<EOT hello world EOT; // add arrays $index_array = array(1, 2, 3); $assoc_array = array('one' => 1, 'two' => 2); // resource $file_handle = fopen(__FILE__, 'r'); //array of values to iterate over $inputs = array('int 0' => 0, 'int 1' => 1, 'int 12345' => 12345, 'int -12345' => -12345, 'float 10.5' => 10.5, 'float -10.5' => -10.5, 'float .5' => 0.5, 'empty array' => array(), 'int indexed array' => $index_array, 'associative array' => $assoc_array, 'nested arrays' => array('foo', $index_array, $assoc_array), 'uppercase NULL' => NULL, 'lowercase null' => null, 'lowercase true' => true, 'lowercase false' => false, 'uppercase TRUE' => TRUE, 'uppercase FALSE' => FALSE, 'empty string DQ' => "", 'empty string SQ' => '', 'string DQ' => "string", 'string SQ' => 'string', 'mixed case string' => "sTrInG", 'heredoc' => $heredoc, 'instance of classWithToString' => new classWithToString(), 'instance of classWithoutToString' => new classWithoutToString(), 'undefined var' => @$undefined_var, 'unset var' => @$unset_var, 'resource' => $file_handle); $object = date_create("2009-02-27 08:34:10"); $year = 1963; $month = 7; foreach ($inputs as $variation => $day) { echo "\n-- {$variation} --\n"; var_dump(date_isodate_set($object, $year, $month, $day)); } // closing the resource fclose($file_handle); ?> ===DONE===
<?php date_default_timezone_set('UTC'); $dto = date_create("2006-12-12"); var_dump(date_isodate_set($dto, 2006, 2, 15)); var_dump($dto->format("Y/m/d H:i:s")); var_dump(date_isodate_set($dto, 2006)); var_dump($dto->format("Y/m/d H:i:s")); var_dump(date_isodate_set($dto, 2006, 5)); var_dump($dto->format("Y/m/d H:i:s")); var_dump(date_isodate_set($dto, 2006, 100, 15)); var_dump($dto->format("Y/m/d H:i:s")); var_dump(date_isodate_set($dto, 2006, 100, 15, 10)); var_dump($dto->format("Y/m/d H:i:s")); echo "Done\n";
function Semana_jueves($year = null, $numero = null) { //funcion que me dice cuando empieza y termina una semana de jueves a jueves //el parametro es el numero de la semana if (!empty($year) && !empty($numero)) { $start_date = date_create(); $end_date = date_create(); date_isodate_set($start_date, $year, $numero); $fecha['start'] = date_format($start_date, 'Y-m-d'); $fecha['start'] = strtotime('+3 day', strtotime($fecha['start'])); $fecha['start'] = date('Y-m-d', $fecha['start']); date_isodate_set($end_date, $year, $numero, 7); $fecha['end'] = date_format($end_date, 'Y-m-d'); $fecha['end'] = strtotime('+3 day', strtotime($fecha['end'])); $fecha['end'] = date('Y-m-d', $fecha['end']); } return $fecha; }
<?php /* Prototype : DateTime date_isodate_set ( DateTime $object , int $year , int $week [, int $day ] ) * Description: Set a date according to the ISO 8601 standard - using weeks and day offsets rather than specific dates. * Source code: ext/date/php_date.c * Alias to functions: DateTime::setISODate */ echo "*** Testing date_isodate_set() : basic functionality ***\n"; //Set the default time zone date_default_timezone_set("Europe/London"); // Create a deate object $datetime = date_create("2009-01-30 17:57:32"); // Which month is week 40 ? date_isodate_set($datetime, 2008, 40); echo "Week 40 of 2009 is in \"" . date_format($datetime, "F") . "\"\n"; // What date is week week 30 day 3 ? date_isodate_set($datetime, 2009, 30, 3); echo "Week 30 day 3 of 2009 is \"" . date_format($datetime, "D M j") . "\"\n"; // What date was is last year ? date_isodate_set($datetime, 2008, 30, 3); echo "..same day last year was \"" . date_format($datetime, "D M j") . "\"\n"; ?> ===DONE===
<?php date_default_timezone_set("America/Los_Angeles"); function format($dt) { var_dump(date_format($dt, "Y-m-d H:i:s")); } format(date_create("2006-12-12"), "2006-12-12 00:00:00"); format(date_create("@1170288001"), "2007-02-01 00:00:01"); $dt = date_create("2006-12-12 12:34:56"); date_date_set($dt, 2007, 11, 23); format($dt); $dt = date_create("2008-08-08 00:00:00"); date_isodate_set($dt, 2007, 35, 3); format($dt); $dt = date_create("2006-12-12 00:00:00"); date_modify($dt, "+1 day"); format($dt); var_dump(date_offset_get(date_create("2006-12-12"))); var_dump(date_offset_get(date_create("2008-08-08"))); $dt = date_create("2006-12-12 12:34:56"); date_time_set($dt, 23, 45, 12); format($dt); $d = strtotime("2008-09-10 12:34:56"); var_dump(date("l", $d)); var_dump(date("l jS \\of F Y h:i:s A", $d)); var_dump(date("l", mktime(0, 0, 0, 7, 1, 2000))); var_dump(date(DATE_RFC822, $d)); var_dump(date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000))); var_dump(date("l \\t\\h\\e jS", $d)); $tomorrow = mktime(0, 0, 0, (int) date("m", $d), (int) date("d", $d) + 1, (int) date("Y", $d));
<?php /* Prototype : DateTime date_isodate_set ( DateTime $object , int $year , int $week [, int $day ] ) * Description: Set a date according to the ISO 8601 standard - using weeks and day offsets rather than specific dates. * Source code: ext/date/php_date.c * Alias to functions: DateTime::setISODate */ //Set the default time zone date_default_timezone_set("Europe/London"); echo "*** Testing date_isodate_set() : error conditions ***\n"; echo "\n-- Testing date_isodate_set() function with zero arguments --\n"; var_dump(date_isodate_set()); $datetime = date_create("2009-01-30 19:34:10"); echo "\n-- Testing date_isodate_set() function with less than expected no. of arguments --\n"; var_dump(date_isodate_set($datetime)); echo "\n-- Testing date_isodate_set() function with more than expected no. of arguments --\n"; $year = 2009; $week = 30; $day = 7; $extra_arg = 30; var_dump(date_isodate_set($datetime, $year, $week, $day, $extra_arg)); echo "\n-- Testing date_isodate_set() function with an invalid values for \$object argument --\n"; $invalid_obj = new stdClass(); var_dump(date_isodate_set($invalid_obj, $year, $week, $day)); $invalid_obj = 10; var_dump(date_isodate_set($invalid_obj, $year, $week, $day)); $invalid_obj = null; var_dump(date_isodate_set($invalid_obj, $year, $week, $day)); ?> ===DONE===