[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /********************************************************************************* 3 ** The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 * 10 ********************************************************************************/ 11 12 class vt_DateTime 13 { 14 var $second = 0; 15 var $minute = 0; 16 var $hour = 0; 17 var $z_hour = '00'; 18 var $day; 19 var $z_day; 20 var $week; 21 var $month; 22 var $z_month; 23 var $year; 24 var $dayofweek; 25 var $dayofyear; 26 var $daysinmonth; 27 var $daysinyear; 28 var $dayofweek_inshort; 29 var $dayofweek_inlong; 30 var $month_inshort; 31 var $month_inlong; 32 var $ts; 33 var $offset; 34 var $format; 35 var $tz; 36 var $ts_def; 37 /** 38 * Constructor for vt_DateTime class 39 * @param array $timearr - collection of string 40 * @param string $check - check string 41 */ 42 function vt_DateTime(&$timearr,$check) 43 { 44 if (! isset( $timearr) || count($timearr) == 0 ) 45 { 46 $this->setDateTime(null); 47 } 48 else if ( isset( $timearr['ts'])) 49 { 50 $this->setDateTime($time['ts']); 51 } 52 else 53 { 54 if(isset($timearr['hour']) && $timearr['hour'] !== '') 55 { 56 $this->hour = $timearr['hour']; 57 } 58 if(isset($timearr['min']) && $timearr['min'] !== '') 59 { 60 $this->minute = $timearr['min']; 61 } 62 if(isset($timearr['sec']) && $timearr['sec'] !== '') 63 { 64 $this->second = $timearr['sec']; 65 } 66 if(isset($timearr['day']) && $timearr['day'] !== '') 67 { 68 $this->day = $timearr['day']; 69 } 70 if(isset($timearr['week']) && $timearr['week'] !== '') 71 { 72 $this->week = $timearr['week']; 73 } 74 if(isset($timearr['month']) && $timearr['month'] !== '') 75 { 76 $this->month = $timearr['month']; 77 } 78 if(isset($timearr['year']) && $timearr['year'] >= 1970) 79 { 80 $this->year = $timearr['year']; 81 } 82 else 83 { 84 return null; 85 } 86 } 87 if ($check) 88 { 89 $this->getDateTime(); 90 } 91 } 92 93 /** 94 * function to get date and time using index 95 * @param integer $index - number between 0 to 23 96 * @param string $day - date 97 * @param string $month - month 98 * @param string $year - year 99 * return vt_DateTime obj $datetimevalue 100 */ 101 function getTodayDatetimebyIndex($index,$day='', $month='', $year=''){ 102 if($day === '') 103 $day = $this->day; 104 if($month === '') 105 $month = $this->month; 106 if($year === '') 107 $year = $this->year; 108 $day_array = array(); 109 110 if($index < 0 || $index > 23){ 111 die("hour is invalid"); 112 } 113 114 $day_array['hour'] = $index; 115 $day_array['min'] = 0; 116 $day_array['day'] = $day; 117 $day_array['month'] = $month; 118 $day_array['year'] = $year; 119 $datetimevalue = new vt_DateTime($day_array,true); 120 return $datetimevalue; 121 } 122 123 /** 124 * function to get days in week using index 125 * @param integer $index - number between 1 to 7 126 * return vt_DateTime obj $datetimevalue 127 */ 128 function getThisweekDaysbyIndex($index){ 129 $week_array = array(); 130 if($index < 1 || $index > 7){ 131 die("day is invalid"); 132 } 133 $week_array['day'] = $this->day + ($index - $this->dayofweek); 134 $week_array['month'] = $this->month; 135 $week_array['year'] = $this->year; 136 $datetimevalue = new vt_DateTime($week_array,true); 137 return $datetimevalue; 138 } 139 140 /** 141 * function to get days in month using index 142 * 143 * This function will be deprecated. 144 * The newer version is getThisMonthsDayByIndex() and should be used wherever possible 145 * 146 * @param integer $index - number between 0 to 42 147 * @param string $day - date 148 * @param string $month - month 149 * @param string $year - year 150 * return vt_DateTime obj $datetimevalue 151 */ 152 153 function getThismonthDaysbyIndex($index,$day='', $month='', $year='') 154 { 155 if($day == '') 156 $day = $index+1; 157 if($month == '') 158 $month = $this->month; 159 if($year == '') 160 $year = $this->year; 161 $month_array = array(); 162 $month_array['day'] = $day; 163 $month_array['month'] = $month; 164 $month_array['year'] = $year; 165 $datetimevalue = new vt_DateTime($month_array,true); 166 return $datetimevalue; 167 } 168 169 /** 170 * function to get months in year using index 171 * @param integer $index - number between 0 to 11 172 * return vt_DateTime obj $datetimevalue 173 */ 174 175 function getThisyearMonthsbyIndex($index) 176 { 177 $year_array = array(); 178 $year_array['day'] = 1; 179 if($index < 0 || $index > 11) 180 { 181 die("month is invalid"); 182 } 183 $year_array['month'] = $index+1; 184 $year_array['year'] = $this->year; 185 $datetimevalue = new vt_DateTime($year_array,true); 186 return $datetimevalue; 187 } 188 189 /** 190 * function to get hour end time 191 * return vt_DateTime obj $datetimevalue 192 */ 193 194 function getHourendtime() 195 { 196 $date_array = array(); 197 $date_array['hour'] = $this->hour; 198 $date_array['min'] = 59; 199 $date_array['day'] = $this->day; 200 $date_array['sec'] = 59; 201 $date_array['month'] = $this->month; 202 $date_array['year'] = $this->year; 203 $datetimevalue = new vt_DateTime($date_array,true); 204 return $datetimevalue; 205 } 206 207 /** 208 * function to get day end time 209 * return vt_DateTime obj $datetimevalue 210 */ 211 function getDayendtime() 212 { 213 $date_array = array(); 214 $date_array['hour'] = 23; 215 $date_array['min'] = 59; 216 $date_array['sec'] = 59; 217 $date_array['day'] = $this->day; 218 $date_array['month'] = $this->month; 219 $date_array['year'] = $this->year; 220 $datetimevalue = new vt_DateTime($date_array,true); 221 return $datetimevalue; 222 } 223 224 /** 225 * function to get month end time 226 * return vt_DateTime obj $datetimevalue 227 */ 228 function getMonthendtime() 229 { 230 $date_array = array(); 231 $date_array['hour'] = 23; 232 $date_array['min'] = 59; 233 $date_array['sec'] = 59; 234 $date_array['day'] = $this->daysinmonth; 235 $date_array['month'] = $this->month; 236 $date_array['year'] = $this->year; 237 $datetimevalue = new vt_DateTime($date_array,true); 238 return $datetimevalue; 239 } 240 241 /** 242 * function to get day of week 243 * return string $this->day - day (eg: Monday) 244 */ 245 function get_Date() 246 { 247 return $this->day; 248 } 249 250 /** 251 * function to get month name in short 252 * return string $this->month_inshort - month name (eg: Jan) 253 */ 254 function getmonthName_inshort(){ 255 return $this->month_inshort; 256 } 257 /** 258 * function to get month 259 * return string $this->month - month name 260 */ 261 function getMonth(){ 262 return $this->month; 263 } 264 /** 265 * function to get year 266 */ 267 function getYear() { 268 return $this->year; 269 } 270 /** 271 * function to get the number of days in a month 272 */ 273 function getDaysInMonth() { 274 return $this->daysinmonth; 275 } 276 /** 277 * function to get month name 278 * return string $this->month_inlong - month name 279 */ 280 function getmonthName(){ 281 return $this->month_inlong; 282 } 283 284 /** 285 * function to get day of week 286 * return string $this->dayofweek_inlong - day of week 287 */ 288 function getdayofWeek(){ 289 return $this->dayofweek_inlong; 290 } 291 /** 292 * function to get day of week in short 293 * return string $this->dayofweek_inshort - day of week (eg: Mon) 294 */ 295 296 function getdayofWeek_inshort(){ 297 return $this->dayofweek_inshort; 298 } 299 300 /** 301 * function to set values for vt_DateTime object 302 * @param integer $ts - Time stamp 303 */ 304 function setDateTime($ts){ 305 global $mod_strings; 306 if (empty($ts)){ 307 $ts = time(); 308 } 309 310 $this->ts = $ts; 311 $this->ts_def = $this->ts; 312 $date_string = date('i::G::H::j::d::t::N::z::L::W::n::m::Y::Z::T::s',$ts); 313 314 list($this->minute,$this->hour,$this->z_hour,$this->day,$this->z_day,$this->daysinmonth,$this->dayofweek,$this->dayofyear,$is_leap,$this->week,$this->month,$this->z_month,$this->year,$this->offset,$this->tz,$this->second) = explode('::',$date_string); 315 316 $this->dayofweek_inshort =$mod_strings['cal_weekdays_short'][$this->dayofweek-1]; 317 $this->dayofweek_inlong=$mod_strings['cal_weekdays_long'][$this->dayofweek-1]; 318 $this->month_inshort=$mod_strings['cal_month_short'][$this->month]; 319 $this->month_inlong=$mod_strings['cal_month_long'][$this->month]; 320 321 $this->daysinyear = 365; 322 323 if ($is_leap == 1){ 324 $this->daysinyear += 1; 325 } 326 } 327 328 /** 329 * function to get values from vt_DateTime object 330 */ 331 function getDateTime() 332 { 333 global $mod_strings; 334 $hour = 0; 335 $minute = 0; 336 $second = 0; 337 $day = 1; 338 $month = 1; 339 $year = 1970; 340 341 if ( isset($this->second) && $this->second !== ''){ 342 $second = $this->second; 343 } 344 if ( isset($this->minute) && $this->minute !== ''){ 345 $minute = $this->minute; 346 } 347 if ( isset($this->hour) && $this->hour !== '') 348 { 349 $hour = $this->hour; 350 } 351 if ( isset($this->day) && $this->day !== ''){ 352 $day= $this->day; 353 } 354 if ( isset($this->month) && $this->month !== ''){ 355 $month = $this->month; 356 } 357 358 if ( isset($this->year) && $this->year !== ''){ 359 $year = $this->year; 360 }else{ 361 die("year was not set"); 362 } 363 if(empty($hour) && $hour !== 0) $hour = 0; 364 $this->ts = mktime($hour,$minute,$second,$month,$day,$year); 365 $this->setDateTime($this->ts); 366 } 367 368 /** 369 * function to get mysql formatted date 370 * return formatted date in string format 371 */ 372 function get_formatted_date(){ 373 $date = $this->year."-".$this->z_month."-".$this->z_day; 374 return DateTimeField::convertToUserFormat($date); 375 } 376 377 /** 378 * Function to get formatted date in users time zone 379 * @return <Date> 380 */ 381 function get_userTimezone_formatted_date(){ 382 $dateTimeInUserFormat = DateTimeField::convertToUserTimeZone($this->get_DB_formatted_date(). ' ' .$this->get_formatted_time()); 383 return $dateTimeInUserFormat->format('Y-m-d'); 384 } 385 386 /** 387 * 388 * @return Date 389 */ 390 function get_DB_formatted_date() { 391 return $this->year."-".$this->z_month."-".$this->z_day; 392 } 393 394 /** 395 * function to get mysql formatted time 396 * return formatted time in string format 397 */ 398 function get_formatted_time(){ 399 $hour = $this->z_hour; 400 $min = $this->minute; 401 if(empty($hour)) $hour = '00'; 402 if(empty($min)) $min = '00'; 403 return $hour.':'.$min; 404 } 405 406 /** 407 * function to get date depends on mode value 408 * @param string $mode - 'increment' or 'decrement' 409 * return vt_DateTime obj 410 */ 411 function get_changed_day($mode){ 412 if($mode == 'increment') 413 $day = $this->day + 1; 414 else 415 $day = $this->day - 1; 416 $date_data = array('day'=>$day, 417 'month'=>$this->month, 418 'year'=>$this->year 419 ); 420 return new vt_DateTime($date_data,true); 421 } 422 423 /** 424 * function to get changed week depends on mode value 425 * @param string $mode - 'increment' or 'decrement' 426 * return vt_DateTime obj 427 */ 428 function get_first_day_of_changed_week($mode){ 429 $first_day = $this->getThisweekDaysbyIndex(1); 430 if($mode == 'increment') 431 $day = $first_day->day + 7; 432 else 433 $day = $first_day->day - 7; 434 $date_data = array('day'=>$day, 435 'month'=>$first_day->month, 436 'year'=>$first_day->year 437 ); 438 return new vt_DateTime($date_data,true); 439 } 440 441 /** 442 * function to get month depends on mode value 443 * @param string $mode - 'increment' or 'decrement' 444 * return vt_DateTime obj 445 */ 446 function get_first_day_of_changed_month($mode){ 447 $tmpDate['day'] = $this->day; 448 $tmpDate['month'] = $this->month; 449 $tmpDate['year'] = $this->year; 450 451 if(is_array($arr) && !empty($arr)){ 452 $tmpDate['year'] = $arr[0]; 453 $tmpDate['month'] = $arr[1]; 454 $tmpDate['day'] = $arr[2]; 455 } 456 457 if($mode == 'increment'){ 458 $month = $tmpDate['month'] + 1; 459 $year = $tmpDate['year'] ; 460 }else{ 461 if($tmpDate['month'] == 1){ 462 $month = 12; 463 $year = $tmpDate['year'] - 1; 464 }else{ 465 $month = $tmpDate['month'] - 1; 466 $year = $tmpDate['year'] ; 467 } 468 } 469 $date_data = array( 470 'day'=>1, 471 'month'=>$month, 472 'year'=>$year 473 ); 474 475 return new vt_DateTime($date_data,true); 476 } 477 478 /** 479 * function to get year depends on mode value 480 * @param string $mode - 'increment' or 'decrement' 481 * return vt_DateTime obj 482 */ 483 function get_first_day_of_changed_year($mode){ 484 if($mode == 'increment'){ 485 $year = $this->year + 1; 486 }else{ 487 $year = $this->year - 1; 488 } 489 $date_data = array('day'=>1, 490 'month'=>1, 491 'year'=>$year 492 ); 493 return new vt_DateTime($date_data,true); 494 } 495 496 /** 497 * function to get date string 498 * return date string 499 */ 500 function get_date_str(){ 501 $array = Array(); 502 if ( isset( $this->hour) && $this->hour != '') 503 { 504 array_push( $array, "hour=".$this->hour); 505 } 506 if ( isset( $this->day) && $this->day != '') 507 { 508 array_push( $array, "day=".$this->day); 509 } 510 if ( isset( $this->month) && $this->month) 511 { 512 array_push( $array, "month=".$this->month); 513 } 514 if ( isset( $this->year) && $this->year != '') 515 { 516 array_push( $array, "year=".$this->year); 517 } 518 return ("&".implode('&',$array)); 519 } 520 521 /** 522 * function to get days in month using index 523 * 524 * This is the newer version of the function getThismonthDaysbyIndex(). 525 * This should be used whereever possible 526 * 527 * @param integer $index - number between 0 to 42 528 * @param string $day - date 529 * @param string $month - month 530 * @param string $year - year 531 * return vt_DateTime obj $datetimevalue 532 */ 533 534 function getThisMonthsDayByIndex($index){ 535 $day = $index; 536 $month = $this->month; 537 $year = $this->year; 538 $month_array = array(); 539 $month_array['day'] = $day; 540 $month_array['month'] = $month; 541 $month_array['year'] = $year; 542 $datetimevalue = new vt_DateTime($month_array,true); 543 return $datetimevalue; 544 } 545 } 546 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |