| Autor | Zpráva | ||
|---|---|---|---|
| Virtus Profil |
#1 · Zasláno: 13. 1. 2014, 16:21:50
Dobrý den, mám tu takový
Kód: private function validatePeriodArrayYear()
{
$this->time->setTimestamp( self::$data['to'] );
$year1 = $this->time->format('Y');
$this->time->setTimestamp( self::$data['from'] );
$year2 = $this->time->format('Y');
$overlap = $year1 - $year2;
if( $overlap > 0 ){
$end = clone $this->time;
$end->setTimestamp( self::$data['to'] );
$interval = new DateInterval('P1Y');
$period = new DatePeriod( $this->time, $interval, $end );
var_dump($period);
$iteration = -1;
foreach( $period as $onePeriod ){ var_dump($onePeriod);
$iteration++;
if( $iteration > 0 ){
$onePeriod->setDate( $onePeriod->format('Y'), 1, 1 );
}
$from = $onePeriod->getTimestamp();
$onePeriod->setDate( $onePeriod->format('Y'), 12, 31 );
$onePeriod->setTime( 23, 59, 59 );
self::$data['zone'][$iteration] = array( 'from' => $from, 'to' => $onePeriod->getTimestamp() );
}
self::$data['zone'][$iteration]['to'] = self::$data['to'];
} else {
self::$data['zone'][] = array( 'from' => self::$data['from'], 'to' => self::$data['to'] );
}
}výstupy: object(DatePeriod)[337] public start => object(DateTime)[336] public date => string 2012-12-01 00:00:00 (length=19) public timezone_type => int 3 public timezone => string Europe/Prague (length=13) public current => null public end => object(DateTime)[48] public date => string 2014-01-13 23:59:59 (length=19) public timezone_type => int 3 public timezone => string Europe/Prague (length=13) public interval => object(DateInterval)[331] public y => int 1 public m => int 0 public d => int 0 public h => int 0 public i => int 0 public s => int 0 public weekday => int 0 public weekday_behavior => int 0 public first_last_day_of => int 0 public invert => int 0 public days => boolean false public special_type => int 0 public special_amount => int 0 public have_weekday_relative => int 0 public have_special_relative => int 0 public recurrences => int 1 public include_start_date => boolean true object(DateTime)[326] public date => string 2012-12-01 00:00:00 (length=19) public timezone_type => int 3 public timezone => string Europe/Prague (length=13) object(DateTime)[47] public date => string 2013-12-01 00:00:00 (length=19) public timezone_type => int 3 public timezone => string Europe/Prague (length=13) self::$data['from'] je roven 1.12:2012 00:00:00 a konečné datum self::$data['to'] je rovno 13.01.2014 23:59:59, výstupem téhle metody je ve výsledku (self::$data['zone']):
01.12.2012 - 31.12.2012 01.01.2013 - 13.01.2014 Tak a teď mně prosím opravte, jestli by to nemělo vygenerovat tohle a kde je v tom případě chyba: 01.12.2012 - 31.12.2012 01.01.2013 - 31.12.2013 01.01.2014 - 13.01.2014 Děkuji za odpovědi |
||
| Virtus Profil |
#2 · Zasláno: 14. 1. 2014, 17:32:21
Tak nakonec sem odpověd dostalo jinde, každopádně až bude někdo řešit podobný problém, tady je odkaz: http://stackoverflow.com/questions/21112036/dateperiod-with-dateinterval-p1y-not-generate-last-year
|
||
|
Časová prodleva: 12 let
|
|||
0