The documentation is incomplete. The Vae Soli! team works hard to make it as exhaustive as possible with tons of useful examples and easy to understand explanations.
On top of that, we have decided to use our own tool to generate the documentation you read. This also takes time to fine-tune. Our goal is have better documentation, easier to read, easier to use, completely integrated with our site.
Even though NOT finalized, you can now link back to our documentation pages as we have decided once and for all about the structure of our documents and where they all reside on our server.
Thank you very much
The Vae Soli! team.
Generated by The Vae Soli! Documentor: Guide v. 1.3.0018 on 01-04-2015 16:19:48 (DD-MM-YYYY HH:mm:SS). This documentation is built with Vae Soli! functions and classes!
The download page of Vae Soli! contains all sources of the framework.
Additional samples are available on the samples page of Vae Soli!.
Assertions count: 102
Assertions successful: 102
Assertion failures: 0
LSDate.functions.php
exceeds 51200 bytes. We suggest this file got broken down in smaller chunks!
LSDate.functions.php
contains 3655 lines of code, which exceeds the suggested limit of 1024 lines. We suggest this file got broken down in smaller chunks!
0001 ... <?php 0002 ... /**************************************************************************/ 0003 ... /** {{{*fheader 0004 ... {*file LSDate.functions.php *} 0005 ... {*purpose Date oriented functions *} 0006 ... {*author Pat Y. Boens *} 0007 ... {*company [br]Lato Sensu Management[br] 0008 ... Rue Bois des Mazuis, 47[br] 0009 ... 5070 Vitrival[br] 0010 ... Belgium (BE)[br] 0011 ... [url]http://www.latosensu.be[/url][br] 0012 ... Vae Soli! : [url]http://www.vaesoli.org[/url] *} 0013 ... {*cdate 26/05/2006 - 15:48 *} 0014 ... {*mdate auto *} 0015 ... {*uses LSStrings.functions.php *} 0016 ... {*license [url]http://creativecommons.org/licenses/by-sa/2.0/be/[/url]. 0017 ... 0018 ... To obtain detailed information about the license 0019 ... terms, please head to the full license text 0020 ... available in the [file]LSCopyright.php[/file] file *} 0021 ... 0022 ... ------------------------------------------------------------------------ 0023 ... Changes History: 0024 ... ------------------------------------------------------------------------ 0025 ... 0026 ... [include]C:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSDate.fuctions.journal[/include] 0027 ... 0028 ... *}}} */ 0029 ... /**************************************************************************/ 0030 ... if ( ! defined( 'LS_DATES_FUNCTIONS_PWH' ) ) 0031 ... { 0032 ... /* {*define (LS_DATES_FUNCTIONS_PWH) Pat Was Here (PWH) *} */ 0033 ... define( 'LS_DATES_FUNCTIONS_PWH','PWH' ); 0034 ... } /* if ( ! defined( 'LS_DATES_FUNCTIONS_PWH' ) ) */ 0035 ... 0036 ... if ( ! defined( 'VAESOLI_PATH' ) ) 0037 ... { 0038 ... /* {*define (VAESOLI_PATH) Define the path where Vae Soli! is installed *} */ 0039 ... define( 'VAESOLI_PATH',__DIR__ ); 0040 ... } /* if ( ! defined( 'VAESOLI_PATH' ) ) */ 0041 ... 0042 ... if ( ! defined( 'VAESOLI_PLUGINS' ) ) 0043 ... { 0044 ... /* {*define (VAESOLI_PLUGINS) Define the path where plugins are located *} */ 0045 ... define( 'VAESOLI_PLUGINS',VAESOLI_PATH . '/../plugins' ); 0046 ... } /* if ( ! defined( 'VAESOLI_PLUGINS' ) ) */ 0047 ... 0048 ... /* {*require (LSStrings.functions.php) Vae Soli! string functions *} */ 0049 ... require_once( VAESOLI_PATH . '/LSStrings.functions.php' ); 0050 ... /* {*require (LSUnitTesting.class.php) Vae Soli! Unit Testing *} */ 0051 ... require_once( VAESOLI_PATH . '/LSUnitTesting.class.php' ); 0052 ... 0053 ... 0054 ... /* ========================================================================== */ 0055 ... /** {{*DAT_Month( $iTime )= 0056 ... 0057 ... Transforms a time value ([c]time()[/c]) into its month equivalent 0058 ... 0059 ... {*params 0060 ... $iTime (int) Optional time (same format as [c]time()[/c]). 0061 ... If not passed, the current time is considered 0062 ... *} 0063 ... 0064 ... {*lupdate 26/12/2012 17:14:52 *} 0065 ... {*version 5.0.0011 *} 0066 ... 0067 ... {*return 0068 ... (int) Month value of the time 0069 ... *} 0070 ... 0071 ... {*exec 0072 ... echo '<p>',$iNow = 1382590417,'</p>'; 0073 ... echo '<p>',$szDate = date( 'YmdHis',$iNow ),'</p>'; 0074 ... 0075 ... echo '<p>',$iMonth = DAT_Month( $iNow ),'</p>'; 0076 ... echo '<p>',$iDay = DAT_Day( $iNow ),'</p>'; 0077 ... echo '<p>',$iYear = DAT_Year( $iNow ),'</p>'; 0078 ... echo '<p>',$iHours = DAT_Hour( $iNow ),'</p>'; 0079 ... echo '<p>',$iMins = DAT_Min( $iNow ),'</p>'; 0080 ... echo '<p>',$iSecs = DAT_Sec( $iNow ),'</p>'; 0081 ... 0082 ... echo LSUnitTesting::assert( $iMonth === (int) substr( $szDate,4,2 ) , 0083 ... 'ASSERTION SUCCESSFUL: month correctly determined' , 0084 ... 'ASSERTION FAILURE: incorrect month' , 0085 ... 'GuideAssert' ); 0086 ... *} 0087 ... 0088 ... {*seealso 0089 ... DAT_Day(), DAT_Year(), DAT_cMonth() 0090 ... *} 0091 ... *}} 0092 ... */ 0093 ... /* ========================================================================== */ 0094 ... function DAT_Month( $iTime = null ) 0095 ... /*-------------------------------*/ 0096 ... { 0097 ... $iRetVal = (int) ( $iTime ? date( 'm',$iTime ) : date( 'm' ) ); 0098 ... return ( $iRetVal ); 0099 ... } /* End of function DAT_Month() ========================================== */ 0100 ... 0101 ... /* ========================================================================== */ 0102 ... /** {{*DAT_Sow( $iWeek[,$iYear] )= 0103 ... 0104 ... Start of the week of $iWeek 0105 ... 0106 ... {*params 0107 ... $iWeek (int) Week number 0108 ... $iYear (int) Year to consider. Optional. 0109 ... Default is current year 0110 ... *} 0111 ... 0112 ... {*mdate 23/10/2013 20:16 *} 0113 ... {*version 5.6.0004 *} 0114 ... 0115 ... {*return 0116 ... (string) Start of the week for $iWeek (YYYYMMDD format) 0117 ... *} 0118 ... 0119 ... {*remark 0120 ... [c]DAT_Bow()[/c] works with a specific date, either in a string format 0121 ... or in an integer format[br] 0122 ... [c]DAT_Sow()[/c] works with a specific week[br] 0123 ... [c]DAT_Eow()[/c] works with a specific week 0124 ... *} 0125 ... 0126 ... {*assert 0127 ... DAT_Sow( 45,2013 ) === '20131104' 0128 ... *} 0129 ... 0130 ... {*seealso 0131 ... DAT_Bow(), DAT_Week2Date(), DAT_Eow() 0132 ... *} 0133 ... 0134 ... *}} 0135 ... */ 0136 ... /* ========================================================================== */ 0137 ... function DAT_Sow( $iWeek = null,$iYear = null ) 0138 ... /*-------------------------------------------*/ 0139 ... { 0140 ... $szDate = null; 0141 ... 0142 ... if ( is_null( $iWeek ) ) 0143 ... { 0144 ... $iWeek = date( 'W' ); 0145 ... } 0146 ... 0147 ... if ( $iWeek > 0 && $iWeek <= 52 ) 0148 ... { 0149 ... $iDate = DAT_Week2Date( $iWeek,$iYear ); 0150 ... $szDate = date( 'Ymd',$iDate ); 0151 ... } 0152 ... 0153 ... return ( $szDate ); 0154 ... } /* End of function DAT_Sow() ============================================ */ 0155 ... 0156 ... /* ========================================================================== */ 0157 ... /** {{*DAT_Eow( $iWeek[,$iYear] )= 0158 ... 0159 ... End of the week of $iWeek 0160 ... 0161 ... {*params 0162 ... $iWeek (int) Week number 0163 ... $iYear (int) Year to consider. Optional. 0164 ... Default is current year 0165 ... *} 0166 ... 0167 ... {*mdate 23/10/2013 20:16 *} 0168 ... {*version 5.6.0004 *} 0169 ... 0170 ... {*return 0171 ... (string) End of the week for $iWeek (YYYYMMDD format) 0172 ... *} 0173 ... 0174 ... {*remark 0175 ... [c]DAT_Bow()[/c] works with a specific date, either in a string format 0176 ... or in an integer format[br] 0177 ... [c]DAT_Sow()[/c] works with a specific week[br] 0178 ... [c]DAT_Eow()[/c] works with a specific week 0179 ... *} 0180 ... 0181 ... {*assert 0182 ... DAT_Eow( 45,2013 ) === '20131110' 0183 ... *} 0184 ... 0185 ... {*assert 0186 ... DAT_Eow( 45,2014 ) === '20141109' 0187 ... *} 0188 ... 0189 ... {*seealso 0190 ... DAT_Week2Date(), DAT_Sow() 0191 ... *} 0192 ... 0193 ... *}} 0194 ... */ 0195 ... /* ========================================================================== */ 0196 ... function DAT_Eow( $iWeek = null,$iYear = null ) 0197 ... /*-------------------------------------------*/ 0198 ... { 0199 ... $szDate = null; 0200 ... 0201 ... if ( is_null( $iWeek ) ) 0202 ... { 0203 ... $iWeek = date( 'W' ); 0204 ... } 0205 ... 0206 ... if ( $iWeek > 0 && $iWeek <= 52 ) 0207 ... { 0208 ... $iDate = DAT_Week2Date( $iWeek,$iYear ) + ( 86400 * 6 ); 0209 ... $szDate = date( 'Ymd',$iDate ); 0210 ... } 0211 ... 0212 ... return ( $szDate ); 0213 ... } /* End of function DAT_Eow() ============================================ */ 0214 ... 0215 ... /* ========================================================================== */ 0216 ... /** {{*DAT_Day( $iTime )= 0217 ... 0218 ... Transforms a time value ([c]time()[/c]) into its day equivalent 0219 ... 0220 ... {*params 0221 ... $iTime (int) Optional time (same format as [c]time()[/c]). 0222 ... If not passed, the current time is considered 0223 ... *} 0224 ... 0225 ... {*return 0226 ... (int) Day value of the time 0227 ... *} 0228 ... 0229 ... {*lupdate 26/12/2012 17:14:52 *} 0230 ... {*version 5.0.0011 *} 0231 ... 0232 ... {*example 0233 ... $iTime = time(); 0234 ... echo "<p>{$iTime} = " . date( "d-m-Y H:i:s",$iTime ) . "</p>"; // 1336805092 = 12-05-2012 06:44:52 0235 ... echo "<p>Day = " . DAT_Day( $iTime ) . "</p>"; // Day = 12 0236 ... *} 0237 ... 0238 ... {*exec 0239 ... echo '<p>',$iNow = 1382590417,'</p>'; 0240 ... echo '<p>',$szDate = date( 'YmdHis',$iNow ),'</p>'; 0241 ... 0242 ... echo '<p>',$iDay = DAT_Day( $iNow ),'</p>'; 0243 ... 0244 ... echo LSUnitTesting::assert( $iDay === (int) substr( $szDate,6,2 ) , 0245 ... 'ASSERTION SUCCESSFUL: day correctly determined', 0246 ... 'ASSERTION FAILURE: incorrect day' , 0247 ... 'GuideAssert' ); 0248 ... *} 0249 ... 0250 ... {*seealso 0251 ... DAT_Month(), DAT_Year(), DAT_Dow(), DAT_cDow() 0252 ... *} 0253 ... *}} 0254 ... */ 0255 ... /* ========================================================================== */ 0256 ... function DAT_Day( $iTime = null ) 0257 ... /*-----------------------------*/ 0258 ... { 0259 ... $iRetVal = (int) ( $iTime ? date( 'd',$iTime ) : date( 'd' ) ); 0260 ... return ( $iRetVal ); 0261 ... } /* End of function DAT_Day() ============================================ */ 0262 ... 0263 ... /* ========================================================================== */ 0264 ... /** {{*DAT_Year( $iTime )= 0265 ... 0266 ... Transforms a time value ([c]time()[/c]) into its year equivalent 0267 ... 0268 ... {*params 0269 ... $iTime (int) Optional time (same format as [c]time()[/c]). 0270 ... If not passed, the current time is considered 0271 ... *} 0272 ... 0273 ... {*return 0274 ... (int) Year value of the time 0275 ... *} 0276 ... 0277 ... {*mdate 26/12/2012 17:14:52 *} 0278 ... {*version 5.0.0011 *} 0279 ... 0280 ... {*example 0281 ... $iTime = time(); 0282 ... echo "<p>{$iTime} = " . date( "d-m-Y H:i:s",$iTime ) . "</p>"; // 1336805092 = 12-05-2012 06:44:52 0283 ... echo "<p>Year = " . DAT_Year( $iTime ) . "</p>"; // Year = 2012 0284 ... *} 0285 ... 0286 ... {*exec 0287 ... echo '<p>',$iNow = 1382590417,'</p>'; 0288 ... echo '<p>',$szDate = date( 'YmdHis',$iNow ),'</p>'; 0289 ... 0290 ... echo '<p>',$iYear = DAT_Year( $iNow ),'</p>'; 0291 ... 0292 ... echo LSUnitTesting::assert( $iYear === (int) substr( $szDate,0,4 ) , 0293 ... 'ASSERTION SUCCESSFUL: year correctly determined', 0294 ... 'ASSERTION FAILURE: incorrect year' , 0295 ... 'GuideAssert' ); 0296 ... *} 0297 ... 0298 ... {*seealso 0299 ... DAT_Month(), DAT_Day() 0300 ... *} 0301 ... 0302 ... *}} 0303 ... */ 0304 ... /* ========================================================================== */ 0305 ... function DAT_Year( $iTime = null ) 0306 ... /*------------------------------*/ 0307 ... { 0308 ... $iRetVal = (int) ( $iTime ? date( 'Y',$iTime ) : date( 'Y' ) ); 0309 ... return ( $iRetVal ); 0310 ... } /* End of function DAT_Year() =========================================== */ 0311 ... 0312 ... /* ========================================================================== */ 0313 ... /** {{*DAT_Hour( $iTime )= 0314 ... 0315 ... Transforms a time value ([c]time()[/c]) into its time (hour) equivalent 0316 ... 0317 ... {*params 0318 ... $iTime (int) Optional time (same format as [c]time()[/c]). 0319 ... If not passed, the current time is considered 0320 ... *} 0321 ... 0322 ... {*return 0323 ... (int) Hour value of the time 0324 ... *} 0325 ... 0326 ... {*lupdate 26/12/2012 17:14:52 *} 0327 ... {*version 5.0.0011 *} 0328 ... 0329 ... {*exec 0330 ... echo '<p>',$iNow = 1382590417,'</p>'; 0331 ... echo '<p>',$szDate = date( 'YmdHis',$iNow ),'</p>'; 0332 ... 0333 ... echo '<p>',$iMonth = DAT_Month( $iNow ),'</p>'; 0334 ... echo '<p>',$iDay = DAT_Day( $iNow ),'</p>'; 0335 ... echo '<p>',$iYear = DAT_Year( $iNow ),'</p>'; 0336 ... echo '<p>',$iHours = DAT_Hour( $iNow ),'</p>'; 0337 ... echo '<p>',$iMins = DAT_Min( $iNow ),'</p>'; 0338 ... echo '<p>',$iSecs = DAT_Sec( $iNow ),'</p>'; 0339 ... 0340 ... echo LSUnitTesting::assert( $iHours === (int) substr( $szDate,8,2 ) , 0341 ... 'ASSERTION SUCCESSFUL: hour correctly determined', 0342 ... 'ASSERTION FAILURE: incorrect hour' , 0343 ... 'GuideAssert' ); 0344 ... *} 0345 ... 0346 ... {*alias 0347 ... DAT_Hours(), TIM_Hour(), TIM_Hours() 0348 ... *} 0349 ... 0350 ... {*seealso 0351 ... DAT_Day(), DAT_Month(), DAT_Year(), DAT_Min(), DAT_Sec() 0352 ... *} 0353 ... 0354 ... *}} 0355 ... */ 0356 ... /* ========================================================================== */ 0357 ... function DAT_Hour( $iTime = null ) 0358 ... /*------------------------------*/ 0359 ... { 0360 ... $iRetVal = (int) ( $iTime ? date( 'H',$iTime ) : date( 'H' ) ); 0361 ... return ( $iRetVal ); 0362 ... } /* End of function DAT_Hour() =========================================== */ 0363 ... function DAT_Hours( $iTime = null ) { return DAT_Hour( $iTime ); } 0364 ... function TIM_Hours( $iTime = null ) { return DAT_Hour( $iTime ); } 0365 ... function TIM_Hour( $iTime = null ) { return DAT_Hour( $iTime ); } 0366 ... 0367 ... /* ========================================================================== */ 0368 ... /** {{*DAT_Min( $iTime )= 0369 ... 0370 ... Transforms a time value ([c]time()[/c]) into its time (min) equivalent 0371 ... 0372 ... {*params 0373 ... $iTime (int) Optional time (same format as [c]time()[/c]). 0374 ... If not passed, the current time is considered 0375 ... *} 0376 ... 0377 ... {*return 0378 ... (int) Minute value of the time 0379 ... *} 0380 ... 0381 ... {*lupdate 26/12/2012 17:14:52 *} 0382 ... {*version 5.0.0011 *} 0383 ... 0384 ... {*example 0385 ... $iNow = time(); 0386 ... 0387 ... $iMonth = DAT_Month( $iNow ); 0388 ... $iDay = DAT_Day( $iNow ); 0389 ... $iYear = DAT_Year( $iNow ); 0390 ... $iHours = DAT_Hour( $iNow ); 0391 ... $iMins = DAT_Min( $iNow ); 0392 ... $iSecs = DAT_Sec( $iNow ); 0393 ... *} 0394 ... 0395 ... {*exec 0396 ... echo '<p>',$iNow = 1382590417,'</p>'; 0397 ... echo '<p>',$szDate = date( 'YmdHis',$iNow ),'</p>'; 0398 ... 0399 ... echo '<p>',$iMins = DAT_Min( $iNow ),'</p>'; 0400 ... 0401 ... echo LSUnitTesting::assert( $iMins === (int) substr( $szDate,10,2 ) , 0402 ... 'ASSERTION SUCCESSFUL: minutes correctly determined', 0403 ... 'ASSERTION FAILURE: incorrect minutes' , 0404 ... 'GuideAssert' ); 0405 ... *} 0406 ... 0407 ... {*alias 0408 ... DAT_Mins(), TIM_Min(), TIM_Mins() 0409 ... *} 0410 ... 0411 ... {*seealso 0412 ... DAT_Day(), DAT_Month(), DAT_Year(), DAT_Hour(), DAT_Sec() 0413 ... *} 0414 ... 0415 ... *}} 0416 ... */ 0417 ... /* ========================================================================== */ 0418 ... function DAT_Min( $iTime = null ) 0419 ... /*------------------------------*/ 0420 ... { 0421 ... $iRetVal = (int) ( $iTime ? date( 'i',$iTime ) : date( 'i' ) ); 0422 ... return ( $iRetVal ); 0423 ... } /* End of function DAT_Min() ============================================ */ 0424 ... function DAT_Mins( $iTime = null ) { return DAT_Min( $iTime ); } 0425 ... function TIM_Mins( $iTime = null ) { return DAT_Min( $iTime ); } 0426 ... function TIM_Min( $iTime = null ) { return DAT_Min( $iTime ); } 0427 ... 0428 ... /* ========================================================================== */ 0429 ... /** {{*DAT_Sec( $iTime )= 0430 ... 0431 ... Transforms a time value ([c]time()[/c]) into its time (sec) equivalent 0432 ... 0433 ... {*params 0434 ... $iTime (int) Optional time (same format as [c]time()[/c]). 0435 ... If not passed, the current time is considered 0436 ... *} 0437 ... 0438 ... {*return 0439 ... (int) Seconds value of the time 0440 ... *} 0441 ... 0442 ... {*lupdate 26/12/2012 17:14:52 *} 0443 ... {*version 5.0.0011 *} 0444 ... 0445 ... {*example 0446 ... $iNow = time(); 0447 ... 0448 ... $iMonth = DAT_Month( $iNow ); 0449 ... $iDay = DAT_Day( $iNow ); 0450 ... $iYear = DAT_Year( $iNow ); 0451 ... $iHours = DAT_Hour( $iNow ); 0452 ... $iMins = DAT_Min( $iNow ); 0453 ... $iSecs = DAT_Sec( $iNow ); 0454 ... *} 0455 ... 0456 ... {*exec 0457 ... echo '<p>',$iNow = 1382590417,'</p>'; 0458 ... echo '<p>',$szDate = date( 'YmdHis',$iNow ),'</p>'; 0459 ... 0460 ... echo '<p>',$iSecs = DAT_Sec( $iNow ),'</p>'; 0461 ... 0462 ... echo LSUnitTesting::assert( $iSecs === (int) substr( $szDate,12,2 ) , 0463 ... 'ASSERTION SUCCESSFUL: secs correctly determined' , 0464 ... 'ASSERTION FAILURE: incorrect secs' , 0465 ... 'GuideAssert' ); 0466 ... *} 0467 ... 0468 ... {*alias 0469 ... DAT_Secs(), TIM_Sec(), TIM_Secs() 0470 ... *} 0471 ... 0472 ... {*seealso 0473 ... DAT_Day(), DAT_Month(), DAT_Year(), DAT_Hour(), DAT_Min() 0474 ... *} 0475 ... 0476 ... *}} 0477 ... */ 0478 ... /* ====================================================================== */ 0479 ... function DAT_Sec( $iTime = null ) 0480 ... /*------------------------------*/ 0481 ... { 0482 ... $iRetVal = (int) ( $iTime ? date( 's',$iTime ) : date( 's' ) ); 0483 ... return ( $iRetVal ); 0484 ... } /* End of function DAT_Sec() ======================================== */ 0485 ... function DAT_Secs( $iTime = null ) { return DAT_Sec( $iTime ); } 0486 ... function TIM_Secs( $iTime = null ) { return DAT_Sec( $iTime ); } 0487 ... function TIM_Sec( $iTime = null ) { return DAT_Sec( $iTime ); } 0488 ... 0489 ... 0490 ... /* ====================================================================== */ 0491 ... /** {{*DAT_Bow( $szDate[,$szFormat] )= 0492 ... 0493 ... Determines the beginning of the week (Monday) of a date 0494 ... 0495 ... {*params 0496 ... $szDate (string) A date string in YYYYMMDD or in a [c]time()[/c] 0497 ... format 0498 ... $szFormat (string) Output format. Optional. null by default in which 0499 ... case the return value is an integer ([c]time()[/c] 0500 ... format) 0501 ... *} 0502 ... 0503 ... {*return 0504 ... (int) Time expressed in number of seconds since 01/01/1970 if 0505 ... $szFormat == null; otherwise a string format (see [c]date()[/c] 0506 ... function in PHP) 0507 ... *} 0508 ... 0509 ... {*cdate 22/07/2012 19:32:47 *} 0510 ... {*mdate 11/10/2014 11:21 *} 0511 ... {*author Pat Y. Boens *} 0512 ... {*version 5.0.0005 *} 0513 ... 0514 ... {*remark 0515 ... [c]DAT_Bow()[/c] works with a specific date, either in a string format 0516 ... or in an integer format[br] 0517 ... [c]DAT_Sow()[/c] works with a specific week[br] 0518 ... [c]DAT_Eow()[/c] works with a specific week 0519 ... *} 0520 ... 0521 ... {*exec 0522 ... echo "<p>" . ( $iTime1 = DAT_Bow( "20120719" ) ) . "</p>"; 0523 ... echo "<p>" . ( $szTime1 = DAT_Bow( "20120719",'Ymd' ) ) . "</p>"; 0524 ... echo "<p>" . ( $iTime2 = DAT_Bow( "20120722" ) ) . "</p>"; 0525 ... echo "<p>" . ( $szTime2 = DAT_Bow( "20120722",'Ymd' ) ) . "</p>"; 0526 ... echo "<p>" . ( $szTime3 = DAT_Bow( TIM_MakeInt( '20141029'),'Ymd' ) ) . "</p>"; 0527 ... 0528 ... echo LSUnitTesting::assert( $iTime1 === 1342396800 , 0529 ... 'ASSERTION SUCCESSFUL: Date of the week correct', 0530 ... 'ASSERTION FAILURE: Date of the week incorrect' , 0531 ... 'GuideAssert' ); 0532 ... echo LSUnitTesting::assert( $iTime2 === 1342396800 , 0533 ... 'ASSERTION SUCCESSFUL: Date of the week correct', 0534 ... 'ASSERTION FAILURE: Date of the week incorrect' , 0535 ... 'GuideAssert' ); 0536 ... echo LSUnitTesting::assert( $szTime1 === '20120716' , 0537 ... 'ASSERTION SUCCESSFUL: Date of the week correct', 0538 ... 'ASSERTION FAILURE: Date of the week incorrect' , 0539 ... 'GuideAssert' ); 0540 ... echo LSUnitTesting::assert( $szTime2 === '20120716' , 0541 ... 'ASSERTION SUCCESSFUL: Date of the week correct', 0542 ... 'ASSERTION FAILURE: Date of the week incorrect' , 0543 ... 'GuideAssert' ); 0544 ... echo LSUnitTesting::assert( $szTime3 === '20141027' , 0545 ... 'ASSERTION SUCCESSFUL: Date of the week correct', 0546 ... 'ASSERTION FAILURE: Date of the week incorrect' , 0547 ... 'GuideAssert' ); 0548 ... *} 0549 ... 0550 ... {*seealso 0551 ... DAT_Sow(), DAT_Dow(), DAT_Eow() 0552 ... *} 0553 ... 0554 ... *}} 0555 ... */ 0556 ... /* ====================================================================== */ 0557 ... function DAT_Bow( $xDate,$szFormat = null ) 0558 ... /*----------------------------------------*/ 0559 ... { 0560 ... if ( is_int( $xDate ) ) 0561 ... { 0562 ... $iTime = $xDate; 0563 ... } 0564 ... else 0565 ... { 0566 ... $iTime = TIM_MakeInt( $xDate ); 0567 ... } 0568 ... 0569 ... $iDay = DAT_Dow( $iTime ); 0570 ... $xRetVal = $xDate; 0571 ... 0572 ... if ( $iDay >= 1 && $iDay <= 7 ) 0573 ... { 0574 ... $aDate = DAT_2Array( is_int( $xDate ) ? date( 'Ymd',$xDate ) : $xDate ); 0575 ... $xRetVal = DAT_Add( (int) $aDate['year'],(int) $aDate['month'],(int) $aDate['day'],-( $iDay - 1 ) ); 0576 ... 0577 ... if ( ! is_null( $szFormat ) ) 0578 ... { 0579 ... $xRetVal = date( $szFormat,$xRetVal ); 0580 ... } 0581 ... } 0582 ... 0583 ... return ( $xRetVal ); 0584 ... } /* End of function DAT_Bow() ============================================ */ 0585 ... 0586 ... /* ========================================================================== */ 0587 ... /** {{*DAT_Boy( $iYear )= 0588 ... 0589 ... Determines the beginning of the year value as an int ([c]time()[/c]) 0590 ... 0591 ... {*params 0592 ... $iYear (integer) The year to consider 0593 ... *} 0594 ... 0595 ... {*return 0596 ... (int) Time expressed in number of seconds since 01/01/1970 0597 ... (use it subsequently with a call to [c]date()[/c]). 0598 ... *} 0599 ... 0600 ... {*cdate 02/01/2013 16:02 *} 0601 ... {*version 5.0.0011 *} 0602 ... 0603 ... {*assert 0604 ... date( 'YmdHis',DAT_Boy( 2013 ) ) === '20130101000000' 0605 ... *} 0606 ... 0607 ... {*exec 0608 ... echo "<p>",$n1 = DAT_Boy( 2012 ),' = ',( $szDate1 = date( 'YmdHis',$n1 ) ),"</p>"; 0609 ... echo "<p>",$n2 = DAT_Boy( 2013 ),' = ',( $szDate2 = date( 'YmdHis',$n2 ) ),"</p>"; 0610 ... 0611 ... echo LSUnitTesting::assert( $n1 === 1325376000 , 0612 ... 'ASSERTION SUCCESSFUL: date correctly determined' , 0613 ... 'ASSERTION FAILURE: incorrect date' , 0614 ... 'GuideAssert' ); 0615 ... echo LSUnitTesting::assert( $szDate1 === '20120101000000' , 0616 ... 'ASSERTION SUCCESSFUL: date correctly determined' , 0617 ... 'ASSERTION FAILURE: incorrect date' , 0618 ... 'GuideAssert' ); 0619 ... *} 0620 ... 0621 ... {*seealso 0622 ... DAT_Eoy() 0623 ... *} 0624 ... 0625 ... *}} 0626 ... */ 0627 ... /* ========================================================================== */ 0628 ... function DAT_Boy( $iYear ) 0629 ... /*----------------------*/ 0630 ... { 0631 ... return ( mktime( 0, // hour 0632 ... 0, // min 0633 ... 0, // sec 0634 ... 1, // month 0635 ... 1, // day 0636 ... $iYear ) ); 0637 ... 0638 ... } /* End of function DAT_Boy() ============================================ */ 0639 ... 0640 ... /* ========================================================================== */ 0641 ... /** {{*DAT_Eoy( $iYear )= 0642 ... 0643 ... Determines the end of the year value as an int ([c]time()[/c]) 0644 ... 0645 ... {*params 0646 ... $iYear (integer) The year to consider 0647 ... *} 0648 ... 0649 ... {*return 0650 ... (int) Time expressed in number of seconds since 01/01/1970 0651 ... (use it subsequently with a call to [c]date()[/c]). 0652 ... *} 0653 ... 0654 ... {*cdate 24/10/2013 09:19 *} 0655 ... {*version 5.6.0004 *} 0656 ... 0657 ... {*exec 0658 ... echo "<p>",$n1 = DAT_Eoy( 2012 ),' = ',( $szDate1 = date( 'YmdHis',$n1 ) ),"</p>"; 0659 ... echo "<p>",$n2 = DAT_Eoy( 2013 ),' = ',( $szDate2 = date( 'YmdHis',$n2 ) ),"</p>"; 0660 ... 0661 ... echo LSUnitTesting::assert( $szDate1 === '20121231235959' , 0662 ... 'ASSERTION SUCCESSFUL: date correctly determined' , 0663 ... 'ASSERTION FAILURE: incorrect date' , 0664 ... 'GuideAssert' ); 0665 ... echo LSUnitTesting::assert( $szDate2 === '20131231235959' , 0666 ... 'ASSERTION SUCCESSFUL: date correctly determined' , 0667 ... 'ASSERTION FAILURE: incorrect date' , 0668 ... 'GuideAssert' ); 0669 ... *} 0670 ... 0671 ... {*seealso 0672 ... DAT_Boy() 0673 ... *} 0674 ... 0675 ... *}} 0676 ... */ 0677 ... /* ========================================================================== */ 0678 ... function DAT_Eoy( $iYear ) 0679 ... /*----------------------*/ 0680 ... { 0681 ... return ( mktime( 23, // hour 0682 ... 59, // min 0683 ... 59, // sec 0684 ... 12, // month 0685 ... 31, // day 0686 ... $iYear ) ); 0687 ... 0688 ... } /* End of function DAT_Eoy() ============================================ */ 0689 ... 0690 ... /* ====================================================================== */ 0691 ... /** {{*DAT_Dow( [$xDate] )= 0692 ... 0693 ... Determines the week of the day value of a given date 0694 ... 0695 ... {*params 0696 ... $xDate (mixed) Date [c]string[/c] in YYYYMMDD format or UNIX time 0697 ... equivalent as an [c]int[/c]. Optional. Defaulted to 0698 ... current time value ([c]time()[/c]). 0699 ... *} 0700 ... 0701 ... {*caution 0702 ... This function behaves differently from PHP (Sunday = 7) 0703 ... *} 0704 ... 0705 ... {*return 0706 ... (int) Day of the week. 1 for Monday; 7 for Sunday. -1 0707 ... in case of error. 0708 ... *} 0709 ... 0710 ... {*cdate 22/07/2012 19:32:47 *} 0711 ... {*version 5.0.0005 *} 0712 ... 0713 ... {*exec 0714 ... echo '<p>' . ( $iDay1 = DAT_Dow( $szDate = "20120722" ) ) . '</p>'; 0715 ... echo '<p>' . ( $iDay2 = DAT_Dow( TIM_MakeInt( $szDate ) ) ) . '</p>'; 0716 ... echo '<p>' . ( $iDay3 = DAT_Dow( null ) ) . '</p>'; 0717 ... echo '<p>' . ( $iDay4 = DAT_Dow() ) . '</p>'; 0718 ... 0719 ... echo LSUnitTesting::assert( $iDay1 === 7 , 0720 ... 'ASSERTION SUCCESSFUL: day of the week correct' , 0721 ... 'ASSERTION FAILURE: incorrect day of the week' , 0722 ... 'GuideAssert' ); 0723 ... echo LSUnitTesting::assert( $iDay2 === $iDay1 , 0724 ... 'ASSERTION SUCCESSFUL: day of the week correct' , 0725 ... 'ASSERTION FAILURE: incorrect day of the week' , 0726 ... 'GuideAssert' ); 0727 ... *} 0728 ... 0729 ... {*seealso 0730 ... TIM_MakeInt() 0731 ... *} 0732 ... *}} 0733 ... */ 0734 ... /* ====================================================================== */ 0735 ... function DAT_Dow( $xDate = null ) 0736 ... /*-----------------------------*/ 0737 ... { 0738 ... if ( is_null( $xDate ) ) /* If NO parameter */ 0739 ... { 0740 ... $iDay = (int) date( 'w' ); /* Use current time */ 0741 ... } 0742 ... elseif ( is_string( $xDate ) ) /* If string passed */ 0743 ... { 0744 ... $iDay = (int) date( 'w',TIM_MakeInt( $xDate ) ); /* Make an int */ 0745 ... } 0746 ... elseif ( is_int( $xDate ) ) /* If int passed */ 0747 ... { 0748 ... $iDay = (int) date( 'w',$xDate ); /* Direct use */ 0749 ... } 0750 ... else /* Houston, we have a problem */ 0751 ... { 0752 ... $iDay = -1; /* Bad return */ 0753 ... } 0754 ... 0755 ... return ( $iDay === 0 ? 7 : $iDay ); /* Return result to caller */ 0756 ... } /* End of function DAT_Dow() ============================================ */ 0757 ... 0758 ... /* ========================================================================== */ 0759 ... /** {{*DAT_cDow( $xDate[,$bLong][,$szLang])= 0760 ... 0761 ... Returns the day of the week from a given date or day in a week 0762 ... 0763 ... {*params 0764 ... $xDate (mixed) Date [c]string[/c] in YYYYMMDD format, or UNIX 0765 ... time equivalent as an [c]int[/c], or day of the 0766 ... week (int between 1 and 7). 0767 ... $bLong (bool) Long (true) or short (false) format. Optional. 0768 ... Long by default. 0769 ... $szLang (string) Language (en,fr or nl). Optional: 'fr' by 0770 ... default. 0771 ... *} 0772 ... 0773 ... {*return 0774 ... (string) Returns the name of the day of the week as a string in 0775 ... proper noun format. 0776 ... *} 0777 ... 0778 ... {*cdate 23/07/2012 14:32:29 *} 0779 ... {*version 5.0.0005 *} 0780 ... 0781 ... {*assert 0782 ... DAT_cDow( 4,false,'fr' ) === 'Je' 0783 ... *} 0784 ... 0785 ... {*assert 0786 ... DAT_cDow( 5,false,'nl' ) === 'Vr' 0787 ... *} 0788 ... 0789 ... {*assert 0790 ... DAT_cDow( 5,true,'nl' ) === 'Vrijdag' 0791 ... *} 0792 ... 0793 ... {*exec 0794 ... echo '<ol>'; 0795 ... echo '<li> ... ',( $szDate01 = DAT_cDow( "20120722" ) ),'</li>'; 0796 ... echo '<li> ... ',( $szDate02 = DAT_cDow( TIM_MakeInt( "20120722" ) ) ),'</li>'; 0797 ... echo '<li> ... ',( $szDate03 = DAT_cDow( null ) ),'</li>'; 0798 ... echo '<li> ... ',( $szDate04 = DAT_cDow( 1,true ,'en' ) ),'</li>'; 0799 ... echo '<li> ... ',( $szDate05 = DAT_cDow( 7,true ,'en' ) ),'</li>'; 0800 ... echo '<li> ... ',( $szDate06 = DAT_cDow( 1,true ,'fr' ) ),'</li>'; 0801 ... echo '<li> ... ',( $szDate07 = DAT_cDow( 7,true ,'fr' ) ),'</li>'; 0802 ... echo '<li> ... ',( $szDate08 = DAT_cDow( 1,true ,'nl' ) ),'</li>'; 0803 ... echo '<li> ... ',( $szDate09 = DAT_cDow( 7,true ,'nl' ) ),'</li>'; 0804 ... echo '<li> ... ',( $szDate10 = DAT_cDow( 3,false ,'fr' ) ),'</li>'; 0805 ... echo '</ol>'; 0806 ... 0807 ... echo LSUnitTesting::assert( strtolower( $szDate01 ) === 'dimanche' , 0808 ... 'ASSERTION SUCCESSFUL: day of the week correctly determined', 0809 ... 'ASSERTION FAILURE: incorrect day of the week' , 0810 ... 'GuideAssert' ); 0811 ... echo LSUnitTesting::assert( strtolower( $szDate09 ) === 'zondag' , 0812 ... 'ASSERTION SUCCESSFUL: day of the week correctly determined', 0813 ... 'ASSERTION FAILURE: incorrect day of the week' , 0814 ... 'GuideAssert' ); 0815 ... echo LSUnitTesting::assert( strtolower( $szDate10 ) === 'me' , 0816 ... 'ASSERTION SUCCESSFUL: day of the week correctly determined', 0817 ... 'ASSERTION FAILURE: incorrect day of the week' , 0818 ... 'GuideAssert' ); 0819 ... *} 0820 ... 0821 ... {*seealso 0822 ... DAT_Day() 0823 ... *} 0824 ... *}} 0825 ... */ 0826 ... /* ====================================================================== */ 0827 ... function DAT_cDow( $xDate,$bLong = true,$szLang = 'fr' ) 0828 ... /*----------------------------------------------------*/ 0829 ... { 0830 ... static $aDays = null; /* Make it static to avoid multiple filling */ 0831 ... static $aMonths = null; /* Make it static to avoid multiple filling */ 0832 ... static $szLanguage = null; /* Language we have treated */ 0833 ... 0834 ... $szRetVal = null; /* Default return value */ 0835 ... 0836 ... if ( is_int( $xDate ) && ( $xDate >= 1 && $xDate <= 7 ) ) /* If integer between 1 and 7 */ 0837 ... { 0838 ... $iDay = $xDate; /* That's the day !!! */ 0839 ... } 0840 ... else 0841 ... { 0842 ... $iDay = DAT_Dow( $xDate ); /* Date of the week (1 to 7; Sunday = 7) */ 0843 ... } 0844 ... 0845 ... if ( $iDay >= 1 && $iDay <= 7 ) /* If day OK */ 0846 ... { 0847 ... if ( is_null( $aDays ) || $szLanguage != $szLang ) /* If NULL ... or if language has changed */ 0848 ... { 0849 ... $aDays = array(); /* Create an array of the days */ 0850 ... $aMonths = array(); /* Create an array for the months */ 0851 ... $szLanguage = $szLang; /* Save language */ 0852 ... DAT_aDaysAndMonths( $aDays,$aMonths,$szLang ); /* Fill array of days and months */ 0853 ... } /* if ( is_null( $aDays ) ) */ 0854 ... 0855 ... if ( $bLong ) /* If long format */ 0856 ... { 0857 ... $szRetVal = $aDays[0][$iDay-1]; /* Return long name */ 0858 ... } 0859 ... else 0860 ... { 0861 ... $szRetVal = $aDays[1][$iDay-1]; /* Return short name */ 0862 ... } 0863 ... } /* if ( $iDay >= 1 && $iDay <= 7 ) */ 0864 ... 0865 ... return ( $szRetVal ); /* Return result to caller */ 0866 ... } /* End of function DAT_cDow() ======================================= */ 0867 ... 0868 ... /* ====================================================================== */ 0869 ... /** {{*DAT_cMonth( $xDate[,$bLong][,$szLang])= 0870 ... 0871 ... Returns the name of the month from a given date or month of year 0872 ... 0873 ... {*params 0874 ... $xDate (mixed) Date [c]string[/c] in YYYYMMDD format, or UNIX time 0875 ... equivalent as an [c]int[/c], or month of the year 0876 ... (int between 1 and 12). 0877 ... $bLong (bool) Long (true) or short (false) format. Optional. Long by default. 0878 ... $szLang (string) Language (en,fr or nl). Optional: 'fr' by default. 0879 ... *} 0880 ... 0881 ... {*return 0882 ... (string) Returns the name of the month as a string in proper noun format 0883 ... *} 0884 ... 0885 ... {*cdate 23/07/2012 16:15:17 *} 0886 ... {*version 5.0.0005 *} 0887 ... 0888 ... {*exec 0889 ... echo '<ol>'; 0890 ... echo '<li> ... ', ( $szDate01 = DAT_cMonth( "20120722" ) ),'</li>'; 0891 ... echo '<li> ... ', ( $szDate02 = DAT_cMonth( TIM_MakeInt( "20120722" ) ) ),'</li>'; 0892 ... echo '<li> ... ', ( $szDate03 = DAT_cMonth( null ) ),'</li>'; 0893 ... echo '<li> ... ', ( $szDate04 = DAT_cMonth( 1,true ,'en' ) ),'</li>'; 0894 ... echo '<li> ... ', ( $szDate05 = DAT_cMonth( 12,true ,'en' ) ),'</li>'; 0895 ... echo '<li> ... ', ( $szDate06 = DAT_cMonth( 1,true ,'fr' ) ),'</li>'; 0896 ... echo '<li> ... ', ( $szDate07 = DAT_cMonth( 12,true ,'fr' ) ),'</li>'; 0897 ... echo '<li> ... ', ( $szDate08 = DAT_cMonth( 1,true ,'nl' ) ),'</li>'; 0898 ... echo '<li> ... ', ( $szDate09 = DAT_cMonth( 12,true ,'nl' ) ),'</li>'; 0899 ... echo '<li> ... ', ( $szDate10 = DAT_cMonth( 6,false,'fr' ) ),'</li>'; 0900 ... echo '</ol>'; 0901 ... 0902 ... echo LSUnitTesting::assert( strtolower( $szDate01 ) === 'juillet' , 0903 ... 'ASSERTION SUCCESSFUL: month of the year correctly determined' , 0904 ... 'ASSERTION FAILURE: incorrect month of the year' , 0905 ... 'GuideAssert' ); 0906 ... echo LSUnitTesting::assert( is_null( $szDate03 ) , 0907 ... 'ASSERTION SUCCESSFUL: month of the year correctly determined' , 0908 ... 'ASSERTION FAILURE: incorrect month of the year' , 0909 ... 'GuideAssert' ); 0910 ... echo LSUnitTesting::assert( strtolower( $szDate07 ) === 'décembre' , 0911 ... 'ASSERTION SUCCESSFUL: month of the year correctly determined' , 0912 ... 'ASSERTION FAILURE: incorrect month of the year' , 0913 ... 'GuideAssert' ); 0914 ... echo LSUnitTesting::assert( strtolower( $szDate09 ) === 'december' , 0915 ... 'ASSERTION SUCCESSFUL: month of the year correctly determined' , 0916 ... 'ASSERTION FAILURE: incorrect month of the year' , 0917 ... 'GuideAssert' ); 0918 ... echo LSUnitTesting::assert( strtolower( $szDate10 ) === 'jun' , 0919 ... 'ASSERTION SUCCESSFUL: month of the year correctly determined' , 0920 ... 'ASSERTION FAILURE: incorrect month of the year' , 0921 ... 'GuideAssert' ); 0922 ... *} 0923 ... 0924 ... {*seealso 0925 ... DAT_Month(), DAT_cDow() 0926 ... *} 0927 ... *}} 0928 ... */ 0929 ... /* ====================================================================== */ 0930 ... function DAT_cMonth( $xDate,$bLong = true,$szLang = 'fr' ) 0931 ... /*------------------------------------------------------*/ 0932 ... { 0933 ... static $aDays = null; /* Make it static to avoid multiple filling */ 0934 ... static $aMonths = null; /* Make it static to avoid multiple filling */ 0935 ... static $szLanguage = null; /* Language we have treated */ 0936 ... 0937 ... $szRetVal = null; /* Default return value */ 0938 ... 0939 ... if ( is_int( $xDate ) ) /* If integer */ 0940 ... { 0941 ... if ( $xDate >= 1 && $xDate <= 12 ) /* If integer between 1 and 12 */ 0942 ... { 0943 ... $iMonth = $xDate; /* That's the month */ 0944 ... } /* if ( $xDate >= 1 && $xDate <= 12 ) */ 0945 ... else /* Else of ... if ( $xDate >= 1 && $xDate <= 12 ) */ 0946 ... { 0947 ... $iMonth = (int) date( 'm',$xDate ); /* We expect $xDate to be a UNIX time */ 0948 ... } /* End of ... Else of ... if ( $xDate >= 1 && $xDate <= 12 ) */ 0949 ... } /* if ( is_int( $xDate ) ) */ 0950 ... elseif ( is_string( $xDate ) ) /* If date string (expected to be a YYYYMMDD format) */ 0951 ... { 0952 ... $iMonth = (int) date( 'm',TIM_MakeInt( $xDate ) ); /* Month of the year (1 to 12) */ 0953 ... } 0954 ... else 0955 ... { 0956 ... $iMonth = 0; 0957 ... } 0958 ... 0959 ... if ( $iMonth >= 1 && $iMonth <= 12 ) /* If month OK */ 0960 ... { 0961 ... if ( is_null( $aDays ) || $szLanguage != $szLang ) /* If NULL ... or if language has changed */ 0962 ... { 0963 ... $aDays = array(); /* Create an array of the days */ 0964 ... $aMonths = array(); /* Create an array for the months */ 0965 ... $szLanguage = $szLang; /* Save language */ 0966 ... DAT_aDaysAndMonths( $aDays,$aMonths,$szLang ); /* Fill array of days and months */ 0967 ... } /* if ( is_null( $aDays ) ) */ 0968 ... 0969 ... if ( $bLong ) /* If long format */ 0970 ... { 0971 ... $szRetVal = $aMonths[0][$iMonth-1]; /* Return long name */ 0972 ... } 0973 ... else 0974 ... { 0975 ... $szRetVal = $aMonths[1][$iMonth-1]; /* Return short name */ 0976 ... } 0977 ... } /* if ( $iMonth >= 1 && $iMonth <= 12 ) */ 0978 ... 0979 ... return ( $szRetVal ); /* Return result to caller */ 0980 ... } /* End of function DAT_cMonth() ========================================= */ 0981 ... 0982 ... /* ========================================================================== */ 0983 ... /** {{*DAT_aDaysAndMonths( $szLang )= 0984 ... 0985 ... Creates arrays of days and months names 0986 ... 0987 ... {*params 0988 ... $szLang (string) The language to consider. Optional. French by default. 0989 ... *} 0990 ... 0991 ... {*cdate 23/07/2012 14:18:22 *} 0992 ... {*version 5.0.0005 *} 0993 ... 0994 ... {*caution 0995 ... Only English, Dutch and French supported 0996 ... *} 0997 ... 0998 ... {*return 0999 ... (void) No return. Arrays passed are updated upon return 1000 ... *} 1001 ... 1002 ... 1003 ... {*exec 1004 ... $aDays = array(); 1005 ... $aMonths = array(); 1006 ... DAT_aDaysAndMonths( $aDays,$aMonths,'en' ); 1007 ... 1008 ... var_dump( $aDays ); 1009 ... var_dump( $aMonths ); 1010 ... 1011 ... echo LSUnitTesting::assert( strtolower( $aDays[0][0] ) === 'monday' , 1012 ... 'ASSERTION SUCCESSFUL: day correctly determined', 1013 ... 'ASSERTION FAILURE: incorrect day' , 1014 ... 'GuideAssert' ); 1015 ... echo LSUnitTesting::assert( strtolower( $aDays[1][0] ) === 'mo' , 1016 ... 'ASSERTION SUCCESSFUL: day correctly determined', 1017 ... 'ASSERTION FAILURE: incorrect day' , 1018 ... 'GuideAssert' ); 1019 ... echo LSUnitTesting::assert( strtolower( $aMonths[0][0] ) === 'january' , 1020 ... 'ASSERTION SUCCESSFUL: month correctly determined' , 1021 ... 'ASSERTION FAILURE: incorrect month' , 1022 ... 'GuideAssert' ); 1023 ... echo LSUnitTesting::assert( strtolower( $aMonths[1][0] ) === 'jan' , 1024 ... 'ASSERTION SUCCESSFUL: month correctly determined' , 1025 ... 'ASSERTION FAILURE: incorrect month' , 1026 ... 'GuideAssert' ); 1027 ... 1028 ... DAT_aDaysAndMonths( $aDays,$aMonths ); 1029 ... 1030 ... var_dump( $aDays[0] ); 1031 ... var_dump( $aMonths[0] ); 1032 ... 1033 ... echo LSUnitTesting::assert( strtolower( $aDays[0][0] ) === 'lundi' , 1034 ... 'ASSERTION SUCCESSFUL: day correctly determined', 1035 ... 'ASSERTION FAILURE: incorrect day' , 1036 ... 'GuideAssert' ); 1037 ... echo LSUnitTesting::assert( strtolower( $aDays[1][0] ) === 'lu' , 1038 ... 'ASSERTION SUCCESSFUL: day correctly determined', 1039 ... 'ASSERTION FAILURE: incorrect day' , 1040 ... 'GuideAssert' ); 1041 ... echo LSUnitTesting::assert( strtolower( $aMonths[0][0] ) === 'janvier' , 1042 ... 'ASSERTION SUCCESSFUL: month correctly determined' , 1043 ... 'ASSERTION FAILURE: incorrect month' , 1044 ... 'GuideAssert' ); 1045 ... echo LSUnitTesting::assert( strtolower( $aMonths[1][0] ) === 'jan' , 1046 ... 'ASSERTION SUCCESSFUL: month correctly determined' , 1047 ... 'ASSERTION FAILURE: incorrect month' , 1048 ... 'GuideAssert' ); 1049 ... 1050 ... 1051 ... *} 1052 ... 1053 ... *}} 1054 ... */ 1055 ... /* ====================================================================== */ 1056 ... function DAT_aDaysAndMonths( &$aDays,&$aMonths,$szLang = 'fr' ) 1057 ... /*-----------------------------------------------------------*/ 1058 ... { 1059 ... switch ( $szLang ) /* Build month and day arrays in function of the language */ 1060 ... { 1061 ... /* -- English --------------------------------------------------------------------------------------------------------- */ 1062 ... case "en" : $aMonths = array( array( "January" ,"February" ,"March" ,"April" ,"May" ,"June" , 1063 ... "July" ,"August" ,"September","October" ,"November" ,"December"), 1064 ... array( "Jan" ,"Feb" ,"Mar" ,"Apr" ,"May" ,"Jun" , 1065 ... "Jul" ,"Aug" ,"Sep" ,"Oct" ,"Nov" ,"Dec" ) ); 1066 ... $aDays = array( array( "Monday" ,"Tuesday" ,"Wednesday","Thursday" ,"Friday" ,"Saturday" ,"Sunday"), 1067 ... array( "Mo" ,"Tu" ,"We" ,"Th" ,"Fr" ,"Sa" ,"Su" ) ); 1068 ... break; 1069 ... /* -- Dutch ----------------------------------------------------------------------------------------------------------- */ 1070 ... case "nl" : $aMonths = array( array( "Januari" ,"Februari" ,"Maart" ,"April" ,"Mei" ,"Juni" , 1071 ... "Juli" ,"Augustus" ,"September","Oktober" ,"November" ,"December"), 1072 ... array( "Janu" ,"Feb" ,"Maa" ,"Apr" ,"Mei" ,"Jun" , 1073 ... "Jul" ,"Aug" ,"Sep" ,"Okt" ,"Nov" ,"Dec" ) ); 1074 ... $aDays = array( array( "Maandag" ,"Dinsdag" ,"Woensdag" ,"Donderdag","Vrijdag" ,"Zaterdag","Zondag"), 1075 ... array( "Ma" ,"Di" ,"Wo" ,"Do" ,"Vr" ,"Za" ,"Zo" ) ); 1076 ... break; 1077 ... /* -- French ---------------------------------------------------------------------------------------------------------- */ 1078 ... default : $aMonths = array( array( "Janvier" ,"Février" ,"Mars" ,"Avril" ,"Mai" ,"Juin" , 1079 ... "Juillet" ,"Août" ,"Septembre","Octobre" ,"Novembre" ,"Décembre"), 1080 ... array( "Jan" ,"Fév" ,"Mar" ,"Avr" ,"Mai" ,"Jun" , 1081 ... "Jul" ,"Aoû" ,"Sep" ,"Oct" ,"Nov" ,"Déc" ) ); 1082 ... $aDays = array( array( "Lundi" ,"Mardi" ,"Mercredi" ,"Jeudi" ,"Vendredi" ,"Samedi","Dimanche"), 1083 ... array( "Lu" ,"Ma" ,"Me" ,"Je" ,"Ve" ,"Sa" ,"Di" ) ); 1084 ... break; 1085 ... } /* switch ( $lang ) */ 1086 ... } /* End of function DAT_aDaysAndMonths() ================================= */ 1087 ... 1088 ... /* ====================================================================== */ 1089 ... /** {{*SetExpiry( $iYear,$iMonth,$iDay,$iHours,$iMinutes,$iSeconds)= 1090 ... 1091 ... Returns an integer that represents an expiry expression 1092 ... 1093 ... {*params 1094 ... $iYear (int) Year of expiry 1095 ... $iMonth (int) Month of expiry 1096 ... $iDay (int) Day of expiry 1097 ... $iHours (int) Hour of expiry. Optional. 1098 ... $iMinutes (int) Minute of expiry. Optional. 1099 ... $iSeconds (int) Second of expiry. Optional. 1100 ... *} 1101 ... 1102 ... {*warning 1103 ... Do not use this function to perform EXACT calculation of expiry. 1104 ... However, you can use this function to compare values returned 1105 ... by the same function. 1106 ... *} 1107 ... 1108 ... {*return 1109 ... (int) Expiry date and time turned to an arbitrary integer. 1110 ... However, you can use SetExpiry() return values between 1111 ... themselves 1112 ... *} 1113 ... 1114 ... {*example 1115 ... echo '<p>',$iDate1=SetExpiry( 2012,12,31,23,59,59 ),'</p>'; // 1972387238399 1116 ... echo '<p>',$iDate2=SetExpiry( 2015,1,1 ),'</p>'; // 1975295980800 1117 ... if ( $iDate2 > $iDate1 ) 1118 ... { 1119 ... echo '<p>$iDate2 > $iDate1</p>'; 1120 ... } 1121 ... *} 1122 ... 1123 ... {*seealso 1124 ... IsExpired() 1125 ... *} 1126 ... 1127 ... *}} 1128 ... */ 1129 ... /* ====================================================================== */ 1130 ... function SetExpiry( $iYear,$iMonth,$iDay,$iHours = 0,$iMinutes = 0,$iSeconds = 0 ) 1131 ... /*-----------------------------------------------------------------------------*/ 1132 ... { 1133 ... $iExpiry = -1; /* Default return value */ 1134 ... 1135 ... $SecondsPerDay = 86400; /* 24 * 60 * 60 */ 1136 ... $SecondsPerMonth = 31 * $SecondsPerDay; /* 31 is arbitrary */ 1137 ... $SecondsPerYear = 366 * $SecondsPerMonth; /* 366 is arbitrary */ 1138 ... 1139 ... $iExpiry = ( $iYear * $SecondsPerYear ) + 1140 ... ( $iMonth * $SecondsPerMonth ) + 1141 ... ( $iDay * $SecondsPerDay ) + 1142 ... ( $iHours * 3600 ) + 1143 ... ( $iMinutes * 60 ) + 1144 ... $iSeconds; 1145 ... 1146 ... return ( $iExpiry ); /* Return the Expiry setting */ 1147 ... } /* End of function SetExpiry() ======================================= */ 1148 ... 1149 ... /* ====================================================================== */ 1150 ... /** {{*IsExpired( $iNow,$iExpired )= 1151 ... 1152 ... Determines whether $iNow is a value that has expired compared to 1153 ... $iExpired 1154 ... 1155 ... {*params 1156 ... $iNow (int) Value to compare to $iExpired 1157 ... $iExpired (int) Basis of comparison 1158 ... *} 1159 ... 1160 ... {*alias 1161 ... HasExpired() 1162 ... *} 1163 ... 1164 ... {*return 1165 ... (bool) true if $iNow > $iExpired 1166 ... *} 1167 ... 1168 ... {*example 1169 ... if ( IsExpired( time(),SetExpiry( 2012,12,31,23,59,59 ) ) ) 1170 ... { 1171 ... echo '<p>Expired!</p>'; 1172 ... } 1173 ... *} 1174 ... 1175 ... {*seealso 1176 ... IsExpired(), SetExpiry(), DAT_IsFuture(), DAT_IsPast() 1177 ... *} 1178 ... 1179 ... *} 1180 ... *}} 1181 ... */ 1182 ... /* ====================================================================== */ 1183 ... function IsExpired( $iNow,$iExpiry ) 1184 ... /*--------------------------------*/ 1185 ... { 1186 ... $bIsExpired = false; /* Not expired by default */ 1187 ... 1188 ... if ( ! is_null( $iExpiry ) ) /* If an expiry has been set */ 1189 ... { 1190 ... $SecondsPerDay = 86400; /* 24 * 60 * 60 */ 1191 ... $SecondsPerMonth = 31 * $SecondsPerDay; /* 31 is arbitrary */ 1192 ... $SecondsPerYear = 366 * $SecondsPerMonth; /* 366 is arbitrary */ 1193 ... 1194 ... $iNow = ( date( "Y",$iNow ) * $SecondsPerYear ) + /* Transform this into a magic date */ 1195 ... ( date( "m",$iNow ) * $SecondsPerMonth ) + 1196 ... ( date( "d",$iNow ) * $SecondsPerDay ) + 1197 ... ( date( "H",$iNow ) * 3600 ) + 1198 ... ( date( "i",$iNow ) * 60 ) + 1199 ... date( "s",$iNow ); 1200 ... 1201 ... $bIsExpired = ( $iNow > $iExpiry ); /* Expired or not ? */ 1202 ... } /* if ( ! is_null( $iExpiry ) ) */ 1203 ... 1204 ... return ( $bIsExpired ); /* Return result to caller */ 1205 ... } /* End of function IsExpired() */ 1206 ... /* ================================================================== */ 1207 ... function HasExpired( $iNow,$iExpiry ) { return ( IsExpired( $iNow,$iExpiry ) ); } 1208 ... 1209 ... /* ====================================================================== */ 1210 ... /** {{*DAT_IsFuture( $szDateTime,$szNow )= 1211 ... 1212 ... Determines whether $szDateTime is in the future (or same) compared to $szNow 1213 ... 1214 ... {*params 1215 ... $szDateTime (string) Date / Time to test ([c]YYYYMMDD[HHmmSS][/c] format) 1216 ... $szNow (string) Optional value to compare $szDateTime with 1217 ... ([c]YYYYMMDD[HHmmSS][/c] format). If not set, 1218 ... [c]date('YmdHis')[/c] is assumed. 1219 ... *} 1220 ... 1221 ... {*return 1222 ... (bool) [c]true[/c] if $szDateTime >= $szNow; [c]false[/c] otherwise 1223 ... *} 1224 ... 1225 ... {*assert ! DAT_IsFuture( '20131231' ,'20131231235959' ) *} 1226 ... {*assert DAT_IsFuture( '20131231150000' ,'20131231' ) *} 1227 ... {*assert ! DAT_IsFuture( '20131231150000' ,'20131231160000' ) *} 1228 ... {*assert DAT_IsFuture( '2013123116' ,'20131231160000' ) *} 1229 ... {*assert ! DAT_IsFuture( '19000101' ) *} 1230 ... 1231 ... {*seealso 1232 ... DAT_IsPast(), SetExpiry(), IsExpired() 1233 ... *} 1234 ... 1235 ... *} 1236 ... *}} 1237 ... */ 1238 ... /* ====================================================================== */ 1239 ... function DAT_IsFuture( $szDateTime,$szNow = null ) 1240 ... /*----------------------------------------------*/ 1241 ... { 1242 ... $bRetVal = false; /* Return value of the function */ 1243 ... 1244 ... if ( ! STR_Empty( $szDateTime ) ) /* If date/time NOT empty */ 1245 ... { 1246 ... $szDateTime = STR_Left( $szDateTime . '000000',14 ); 1247 ... 1248 ... if ( is_null ( $szNow ) ) 1249 ... $szNow = date( 'YmdHis' ); 1250 ... else 1251 ... $szNow = STR_Left( $szNow . '000000',14 ); 1252 ... 1253 ... $bRetVal = $szDateTime >= $szNow; 1254 ... } 1255 ... 1256 ... return ( $bRetVal ); /* Return result to caller */ 1257 ... 1258 ... } /* End of function DAT_IsFuture() =================================== */ 1259 ... 1260 ... /* ====================================================================== */ 1261 ... /** {{*DAT_IsPast( $szDateTime,$szNow )= 1262 ... 1263 ... Determines whether $szDateTime is in the past (or same) compared to $szNow 1264 ... 1265 ... {*params 1266 ... $szDateTime (string) Date / Time to test ([c]YYYYMMDD[HHmmSS][/c] format) 1267 ... $szNow (string) Optional value to compare $szDateTime with 1268 ... ([c]YYYYMMDD[HHmmSS][/c] format). If not set, 1269 ... [c]date('YmdHis')[/c] is assumed. 1270 ... *} 1271 ... 1272 ... {*return 1273 ... (bool) [c]true[/c] if $szDateTime <= $szNow; [c]false[/c] otherwise 1274 ... *} 1275 ... 1276 ... {*assert 1277 ... DAT_IsPast( '20131231','20131231235959' ) == true 1278 ... *} 1279 ... 1280 ... {*assert 1281 ... DAT_IsPast( '20131231150000', '20131231' ) == true 1282 ... *} 1283 ... 1284 ... {*assert 1285 ... DAT_IsPast( '20150101', '20140101' ) == false 1286 ... *} 1287 ... 1288 ... {*assert 1289 ... DAT_IsPast( '20140101', '20150101' ) == true 1290 ... *} 1291 ... 1292 ... {*exec 1293 ... if ( DAT_IsPast( $dt1 = '20131231',$dt2 = '20131231235959' ) ) 1294 ... echo "<p>{$dt1} <= {$dt2}</p>"; 1295 ... else 1296 ... echo "<p>{$dt1} > {$dt2}</p>"; 1297 ... 1298 ... if ( DAT_IsPast( $dt1 = '20131231150000',$dt2 = '20131231' ) ) 1299 ... echo "<p>{$dt1} <= {$dt2}</p>"; 1300 ... else 1301 ... echo "<p>{$dt1} > {$dt2}</p>"; 1302 ... if ( DAT_IsPast( $dt1 = '20131231150000',$dt2 = '20131231160000' ) ) 1303 ... echo "<p>{$dt1} <= {$dt2}</p>"; 1304 ... else 1305 ... echo "<p>{$dt1} > {$dt2}</p>"; 1306 ... if ( DAT_IsPast( $dt1 = '20131231130000',$dt2 = '20131231160000' ) ) 1307 ... echo "<p>{$dt1} <= {$dt2}</p>"; 1308 ... else 1309 ... echo "<p>{$dt1} > {$dt2}</p>"; 1310 ... *} 1311 ... 1312 ... {*seealso 1313 ... DAT_IsFuture(), SetExpiry(), IsExpired() 1314 ... *} 1315 ... *}} 1316 ... */ 1317 ... /* ====================================================================== */ 1318 ... function DAT_IsPast( $szDateTime,$szNow = null ) 1319 ... /*----------------------------------------------*/ 1320 ... { 1321 ... $bRetVal = false; /* Return value of the function */ 1322 ... 1323 ... if ( ! STR_Empty( $szDateTime ) ) /* If date/time NOT empty */ 1324 ... { 1325 ... $szDateTime = STR_Left( $szDateTime . '235959',14 ); /* Pad it with a end of the day (23:59:59) */ 1326 ... 1327 ... if ( is_null ( $szNow ) ) 1328 ... $szNow = date( 'YmdHis' ); 1329 ... else 1330 ... $szNow = STR_Left( $szNow . '235959',14 ); 1331 ... 1332 ... $bRetVal = $szDateTime <= $szNow; 1333 ... } 1334 ... 1335 ... return ( $bRetVal ); /* Return result to caller */ 1336 ... 1337 ... } /* End of function DAT_IsPast() ===================================== */ 1338 ... 1339 ... /* ====================================================================== */ 1340 ... /** {{*TIM_MakeInt( $szDTOS )= 1341 ... 1342 ... Transforms a DTOS value (YYYYMMDD) into an integer 1343 ... 1344 ... {*params 1345 ... $szDTOS (string) Optional time (same format as [c]time()[/c]). 1346 ... If not passed, the current time is considered 1347 ... *} 1348 ... 1349 ... {*return 1350 ... (int) $szDTOS (YYYYMMDD) turned to an integer 1351 ... *} 1352 ... 1353 ... {*example 1354 ... echo '<p>',TIM_MakeInt( "20120512" ),'</p>'; // 1336780800 1355 ... echo '<p>',date( 'Ymd',1336780800 ),'</p>'; // 20120512 1356 ... *} 1357 ... 1358 ... {*seealso 1359 ... TIM_Add() 1360 ... *} 1361 ... 1362 ... *}} 1363 ... */ 1364 ... /* ====================================================================== */ 1365 ... function TIM_MakeInt( $szDTOS ) 1366 ... /*---------------------------*/ 1367 ... { 1368 ... $iRetVal = -1; /* Default return va;lue of the function */ 1369 ... 1370 ... //echo "<p>DTOS: {$szDTOS}</p>\n"; 1371 ... if ( ! STR_Empty( $szDTOS ) ) /* If parameter OK */ 1372 ... { 1373 ... $i = strtotime( $szDTOS ); /* Make this a time value */ 1374 ... 1375 ... if ( is_numeric( $i ) ) /* If numeric value */ 1376 ... { 1377 ... //echo "<p>" . date('Y/m/d H:i:s',$i) . "</p>\n"; 1378 ... $iRetVal = (int) $i; /* Turn it to an integer */ 1379 ... } /* if ( is_numeric( $i ) ) */ 1380 ... } /* if ( $szDTOS && strlen( $szDTOS ) ) */ 1381 ... 1382 ... return ( $iRetVal ); /* Return result to caller */ 1383 ... } /* End of function TIM_MakeInt() ==================================== */ 1384 ... 1385 ... /* ====================================================================== */ 1386 ... /** {{*TIM_IsBetween( $iNow,$szStart,$szStop )= 1387 ... 1388 ... Determines whether $iNow is between $szStart and $szStop 1389 ... 1390 ... {*params 1391 ... $iNow (int) Value to compare 1392 ... $szStart (string) Time interval start value (HH:MM:SS) 1393 ... $szStop (string) Time interval stop value (HH:MM:SS) 1394 ... *} 1395 ... 1396 ... {*return 1397 ... (bool) true if $szStart <= $iNow <= $szStop; false otherwise 1398 ... *} 1399 ... 1400 ... {*example 1401 ... if ( TIM_IsBetween( time(),'12:00:00','13:00:00' ) ) 1402 ... { 1403 ... echo '<p>Lunch time!</p>'; 1404 ... } 1405 ... *} 1406 ... 1407 ... *}} 1408 ... */ 1409 ... /* ====================================================================== */ 1410 ... function TIM_IsBetween( $iNow,$szStart,$szStop ) 1411 ... /*--------------------------------------------*/ 1412 ... { 1413 ... $szStart = STR_dionly( $szStart ); 1414 ... $szStop = STR_dionly( $szStop ); 1415 ... 1416 ... $iTimeStart = mktime( substr( $szStart,0,2 ), /* Hours */ 1417 ... substr( $szStart,2,2 ), /* Minutes */ 1418 ... substr( $szStart,4,2 ) ); /* Seconds */ 1419 ... 1420 ... $iTimeStop = mktime( substr( $szStop ,0,2 ), /* Hours */ 1421 ... substr( $szStop ,2,2 ), /* Minutes */ 1422 ... substr( $szStop ,4,2 ) ); /* Seconds */ 1423 ... 1424 ... //echo "<p>{$iTimeStart}</p>\n"; 1425 ... //echo "<p>{$iNow}</p>\n"; 1426 ... //echo "<p>{$iTimeStop}</p>\n"; 1427 ... 1428 ... return ( $iNow < $iTimeStart ? false : ( $iNow <= $iTimeStop ) );/* Return result to caller */ 1429 ... } /* End of function TIM_IsBetween() ================================== */ 1430 ... 1431 ... /* ====================================================================== */ 1432 ... function TIM_DaylightSavingTime( $iPeriod,$szRegion = 'EU' ) 1433 ... /*--------------------------------------------------------*/ 1434 ... { 1435 ... $iRetVal = -1; /* Return value of the function */ 1436 ... 1437 ... if ( $szRegion == 'EU' ) /* If Europe */ 1438 ... { 1439 ... if ( $iPeriod == 1 ) /* If "heure d'été" */ 1440 ... { 1441 ... $iEndOfMarch = mktime( 0,0,0,3,31,date('Y') ); 1442 ... $iDayOfTheWeek = date( 'N',$iEndOfMarch ); 1443 ... if ( $iDayOfTheWeek == 7 ) 1444 ... $iLastSundayOfMarch = $iEndOfMarch; 1445 ... else 1446 ... $iLastSundayOfMarch = $iEndOfMarch - ( $iDayOfTheWeek * 86400 ); 1447 ... 1448 ... $iRetVal = $iLastSundayOfMarch; 1449 ... } 1450 ... else /* Heure d'hiver */ 1451 ... { 1452 ... $iEndOfOctober = mktime( 0,0,0,10,31,date('Y') ); 1453 ... $iDayOfTheWeek = date( 'N',$iEndOfOctober ); 1454 ... if ( $iDayOfTheWeek == 7 ) 1455 ... $iLastSundayOfOctober = $iEndOfOctober; 1456 ... else 1457 ... $iLastSundayOfOctober = $iEndOfOctober - ( $iDayOfTheWeek * 86400 ); 1458 ... 1459 ... $iRetVal = $iLastSundayOfOctober; 1460 ... } 1461 ... } 1462 ... else /* If United States */ 1463 ... { 1464 ... // Bon ... ici ... rien n'est bon 1465 ... // le début de l'heure d'été c'est le 2ème dimanche de mars 1466 ... // le début de l'heure d'hiver c'est le 1er dimanche de novembre!!! 1467 ... if ( $iPeriod == 1 ) /* If "heure d'été" */ 1468 ... { 1469 ... $iEndOfMarch = mktime( 0,0,0,3,31,date('Y') ); 1470 ... $iDayOfTheWeek = date( 'N',$iEndOfMarch ); 1471 ... if ( $iDayOfTheWeek == 7 ) 1472 ... $iLastSundayOfMarch = $iEndOfMarch; 1473 ... else 1474 ... $iLastSundayOfMarch = $iEndOfMarch - ( $iDayOfTheWeek * 86400 ); 1475 ... 1476 ... $iRetVal = $iLastSundayOfMarch; 1477 ... } 1478 ... else /* Heure d'hiver */ 1479 ... { 1480 ... $iEndOfOctober = mktime( 0,0,0,10,31,date('Y') ); 1481 ... $iDayOfTheWeek = date( 'N',$iEndOfOctober ); 1482 ... if ( $iDayOfTheWeek == 7 ) 1483 ... $iLastSundayOfOctober = $iEndOfOctober; 1484 ... else 1485 ... $iLastSundayOfOctober = $iEndOfOctober - ( $iDayOfTheWeek * 86400 ); 1486 ... 1487 ... $iRetVal = $iLastSundayOfOctober; 1488 ... } 1489 ... } 1490 ... 1491 ... return ( $iRetVal ); /* Return result to caller */ 1492 ... } /* End of function TIM_DaylightSavingTime() ========================= */ 1493 ... 1494 ... /* ====================================================================== */ 1495 ... /** {{*TIM_Stot( $szYYYYMMDDHHmmSS )= 1496 ... 1497 ... Creates a time value ([c]time()[/c]) from a [c]YYYYMMDDHHmmSS[/c] value 1498 ... 1499 ... {*params 1500 ... $szYYYYMMDDHHmmSS (string) Time string ([c]YYYYMM[DD[HH[mm[SS]]]][/c]) 1501 ... *} 1502 ... 1503 ... {*alias 1504 ... DAT_Stot(), DAT_Stod() 1505 ... *} 1506 ... 1507 ... {*return 1508 ... (int) Time value of $szYYYYMMDDHHmmSS 1509 ... *} 1510 ... 1511 ... {*example 1512 ... echo TIM_Stot( '20120512164800' ); // 1336841280 1513 ... echo date( 'YmdHis',1336841280 ); // 20120512164800 1514 ... *} 1515 ... 1516 ... {*exec 1517 ... echo "<p>",( $iTime = TIM_Stot( '20130203155959') ),' - ',date( 'd-m-Y H:i:s',$iTime ),"</p>"; 1518 ... echo "<p>",( $iTime = TIM_Stot( '201302031559' ) ),' - ',date( 'd-m-Y H:i:s',$iTime ),"</p>"; 1519 ... echo "<p>",( $iTime = TIM_Stot( '2013020315' ) ),' - ',date( 'd-m-Y H:i:s',$iTime ),"</p>"; 1520 ... echo "<p>",( $iTime = TIM_Stot( '20130203' ) ),' - ',date( 'd-m-Y H:i:s',$iTime ),"</p>"; 1521 ... echo "<p>",( $iTime = TIM_Stot( '201302' ) ),' - ',date( 'd-m-Y H:i:s',$iTime ),"</p>"; 1522 ... echo "<p>",( $iTime = TIM_Stot( 'hello' ) ) ,"</p>"; 1523 ... *} 1524 ... 1525 ... {*assert 1526 ... date( 'd-m-Y H:i:s',TIM_Stot( '20130203155959') ) === '03-02-2013 15:59:59' 1527 ... *} 1528 ... 1529 ... {*assert 1530 ... date( 'd-m-Y H:i:s',TIM_Stot( '201302031559' ) ) === '03-02-2013 15:59:00' 1531 ... *} 1532 ... 1533 ... {*assert 1534 ... date( 'd-m-Y H:i:s',TIM_Stot( '2013020315' ) ) === '03-02-2013 15:00:00' 1535 ... *} 1536 ... 1537 ... {*assert 1538 ... date( 'd-m-Y H:i:s',TIM_Stot( '20130203' ) ) === '03-02-2013 00:00:00' 1539 ... *} 1540 ... 1541 ... {*assert 1542 ... date( 'd-m-Y H:i:s',TIM_Stot( '201302' ) ) === '01-02-2013 00:00:00' 1543 ... *} 1544 ... 1545 ... {*assert 1546 ... TIM_Stot( 'hello' ) === -1 1547 ... *} 1548 ... 1549 ... {*seealso 1550 ... TIM_MakeInt(), DAT_dtos() 1551 ... *} 1552 ... *}} 1553 ... */ 1554 ... /* ====================================================================== */ 1555 ... function TIM_Stot( $szYYYYMMDDHHmmSS ) 1556 ... /*----------------------------------*/ 1557 ... { 1558 ... if ( STR_Empty( $szYYYYMMDDHHmmSS = STR_Dionly( $szYYYYMMDDHHmmSS ) ) ) 1559 ... return ( -1 ); 1560 ... 1561 ... $iLength = strlen( $szYYYYMMDDHHmmSS ); 1562 ... 1563 ... $iSeconds = 1564 ... $iMinutes = 1565 ... $iHours = 0; 1566 ... 1567 ... switch ( $iLength ) 1568 ... { 1569 ... case 14: $iSeconds = substr( $szYYYYMMDDHHmmSS,12,2 ); 1570 ... case 12: $iMinutes = substr( $szYYYYMMDDHHmmSS,10,2 ); 1571 ... case 10: $iHours = substr( $szYYYYMMDDHHmmSS, 8,2 ); 1572 ... } /* switch ( $iLength ) */ 1573 ... 1574 ... $iYear = (int) substr( $szYYYYMMDDHHmmSS,0,4 ); /* Year */ 1575 ... $iMonth = (int) substr( $szYYYYMMDDHHmmSS,4,2 ); /* Month */ 1576 ... 1577 ... if ( $iLength > 6 ) 1578 ... $iDay = (int) substr( $szYYYYMMDDHHmmSS,6,2 ); /* Day */ 1579 ... else 1580 ... $iDay = 1; 1581 ... 1582 ... //echo "<p>Original: " . $szYYYYMMDDHHmmSS . "</p>\n"; 1583 ... //echo "<p>Length: " . $iLength . "</p>\n"; 1584 ... //echo "<p>Year : " . substr( $szYYYYMMDDHHmmSS,0,4 ) . "</p>\n"; 1585 ... //echo "<p>Month: " . substr( $szYYYYMMDDHHmmSS,4,2 ) . "</p>\n"; 1586 ... //echo "<p>Day : " . substr( $szYYYYMMDDHHmmSS,6,2 ) . "</p>\n"; 1587 ... 1588 ... return ( mktime( $iHours,$iMinutes,$iSeconds,$iMonth,$iDay,$iYear ) ); 1589 ... } /* End of function TIM_Stot() =========================================== */ 1590 ... function DAT_Stot( $x ) { return ( TIM_Stot( $x ) ); } 1591 ... function DAT_Stod( $x ) { return ( TIM_Stot( $x ) ); } 1592 ... 1593 ... /* ========================================================================== */ 1594 ... /** {{*DAT_dtos( $xDate )= 1595 ... 1596 ... Turns a [c]DD/MM/YYYY[/c] date or an int into a [c]YYYYMMDD[/c] date format 1597 ... 1598 ... {*params 1599 ... $xDate (string|int) Date string ([c]DD/MM/YYYY[/c] or 1600 ... [c]YYYY/MM/DD[/c] format). If $xDate is an 1601 ... integer, then it is treated as if it were a 1602 ... [c]time()[/c] value 1603 ... *} 1604 ... 1605 ... {*return 1606 ... (string) $xDate turned to a [c]YYYYMMDD[/c] format; [c]null[/c] if 1607 ... incorrect $xDate. 1608 ... *} 1609 ... 1610 ... {*exec 1611 ... echo DAT_dtos( '01/01/2012' ); 1612 ... echo DAT_dtos( '48/7/3013' ); 1613 ... *} 1614 ... 1615 ... {*assert 1616 ... DAT_dtos( '01/01/2012' ) === '20120101' 1617 ... *} 1618 ... 1619 ... {*assert 1620 ... DAT_dtos( '31/12/2013' ) === '20131231' 1621 ... *} 1622 ... 1623 ... {*assert 1624 ... is_null( DAT_dtos( '48/7/2013' ) ) 1625 ... *} 1626 ... 1627 ... {*seealso 1628 ... TIM_Stot() 1629 ... *} 1630 ... *}} 1631 ... */ 1632 ... /* ========================================================================== */ 1633 ... function DAT_dtos( $xDate ) 1634 ... /*------------------------*/ 1635 ... { 1636 ... $szRetVal = null; /* Return value of the method */ 1637 ... 1638 ... if ( is_string( $xDate ) ) 1639 ... { 1640 ... $xDate = trim( $xDate ); /* Eliminate leading and trailing spaces */ 1641 ... 1642 ... if ( strlen( $xDate ) === 10 ) /* If valid length */ 1643 ... { 1644 ... if ( preg_match( '%(?P<year>\d{4})[-/.](?P<month>\d{2})[-/.](?P<day>\d{2})%',$xDate,$aMatch ) ) 1645 ... { 1646 ... $szRetVal = $aMatch['year'] . $aMatch['month'] . $aMatch['day']; 1647 ... } /* if ( preg_match( '...',$xDate,$aMatch ) ) */ 1648 ... else /* Else of ... if ( preg_match( '...',$xDate,$aMatch ) ) */ 1649 ... { 1650 ... $szRetVal = substr( $xDate,6,4 ) . 1651 ... substr( $xDate,3,2 ) . 1652 ... substr( $xDate,0,2 ); 1653 ... } /* End of ... Else of ... if ( preg_match( '...',$xDate,$aMatch ) ) */ 1654 ... } /* if ( strlen( $xDate ) === 10 ) */ 1655 ... } 1656 ... elseif ( is_integer( $xDate ) ) 1657 ... { 1658 ... $szRetVal = date( 'Ymd',$xDate ); 1659 ... } 1660 ... 1661 ... return ( $szRetVal ); /* Return result to caller */ 1662 ... } /* End of function DAT_dtos() =========================================== */ 1663 ... 1664 ... /* ========================================================================== */ 1665 ... /** {{*DAT_Split( $szDate )= 1666 ... 1667 ... Splits a YYYYMMDD[HHmmSS] date into an associative array 1668 ... 1669 ... {*params 1670 ... $szDate (string) A YYYYMMDD[HHmmSS] date string 1671 ... *} 1672 ... 1673 ... {*return 1674 ... (array)[br] [c]a['year'] [/c] = YYYY[br] 1675 ... [c]a['month'][/c] = MM[br] 1676 ... [c]a['day'] [/c] = DD[br] 1677 ... [c]a['hour'] [/c] = HH[br] 1678 ... [c]a['min'] [/c] = mm[br] 1679 ... [c]a['sec'] [/c] = SS[br] 1680 ... *} 1681 ... 1682 ... {*uses 1683 ... STR_Empty(), STR_dionly() 1684 ... *} 1685 ... 1686 ... {*exec 1687 ... $aDate = DAT_Split( '20120616140959' ); 1688 ... echo "<p>{$aDate['year']}</p>"; 1689 ... echo "<p>{$aDate['month']}</p>"; 1690 ... echo "<p>{$aDate['day']}</p>"; 1691 ... echo "<p>{$aDate['hour']}</p>"; 1692 ... echo "<p>{$aDate['min']}</p>"; 1693 ... echo "<p>{$aDate['sec']}</p>"; 1694 ... *} 1695 ... 1696 ... {*seealso 1697 ... DAT_2Array() 1698 ... *} 1699 ... *}} 1700 ... */ 1701 ... /* ====================================================================== */ 1702 ... function DAT_Split( $szDate ) 1703 ... /*-------------------------*/ 1704 ... { 1705 ... $aRetVal = array(); /* Return value of the method */ 1706 ... $aRetVal['year'] = null; /* Prepare slot */ 1707 ... $aRetVal['month'] = null; /* Prepare slot */ 1708 ... $aRetVal['day'] = null; /* Prepare slot */ 1709 ... $aRetVal['hour'] = null; /* Prepare slot */ 1710 ... $aRetVal['min'] = null; /* Prepare slot */ 1711 ... $aRetVal['sec'] = null; /* Prepare slot */ 1712 ... 1713 ... //die( __METHOD__ . ' ... ' . $szDate ); 1714 ... 1715 ... if ( ! STR_Empty( $szDate ) ) /* If valid argument */ 1716 ... { 1717 ... $szDate = STR_dionly( $szDate ); /* Eliminate all unwanted characters */ 1718 ... $iLength = strlen( $szDate ); 1719 ... 1720 ... if ( $iLength >= 4 ) /* If valid length */ 1721 ... $aRetVal['year'] = (int) substr( $szDate,0,4 ); 1722 ... 1723 ... if ( $iLength >= 6 ) /* If valid length */ 1724 ... $aRetVal['month'] = (int) substr( $szDate,4,2 ); 1725 ... 1726 ... if ( $iLength >= 8 ) /* If valid length */ 1727 ... $aRetVal['day'] = (int) substr( $szDate,6,2 ); 1728 ... 1729 ... if ( $iLength >= 10 ) /* If valid length */ 1730 ... $aRetVal['hour'] = (int) substr( $szDate,8,2 ); 1731 ... 1732 ... if ( $iLength >= 12 ) /* If valid length */ 1733 ... $aRetVal['min'] = (int) substr( $szDate,10,2 ); 1734 ... 1735 ... if ( $iLength >= 14 ) /* If valid length */ 1736 ... $aRetVal['sec'] = (int) substr( $szDate,12,2 ); 1737 ... 1738 ... } /* if ( ! is_null( $szDate ) ) */ 1739 ... else 1740 ... { 1741 ... //die( __METHOD__ . ' ... date vide ... ' . $szDate ); 1742 ... } 1743 ... 1744 ... return ( $aRetVal ); /* Return result to caller */ 1745 ... } /* End of function DAT_split() */ 1746 ... /* ====================================================================== */ 1747 ... 1748 ... /* ====================================================================== */ 1749 ... /** {{*DAT_Add( $iYear,$iMonth,$iDay,$iAdd )= 1750 ... 1751 ... Adds or substracts a number of days to/from a date 1752 ... 1753 ... {*params 1754 ... $iYear (int) Year 1755 ... $iMonth (int) Month 1756 ... $iDay (int) Day 1757 ... $iAdd (int) Number of days to add (+) or to substract (-) 1758 ... *} 1759 ... 1760 ... {*return 1761 ... (int) [c]mktime()[/c] expression 1762 ... *} 1763 ... 1764 ... {*assert 1765 ... DAT_Add( 2012,5,12,4 ) == '1337126400' 1766 ... *} 1767 ... 1768 ... {*assert 1769 ... DAT_Add( 2012,5,12,4 ) === 1337126400 1770 ... *} 1771 ... 1772 ... {*assert 1773 ... DAT_Add( 2012,5,12,-1 ) === 1336694400 1774 ... *} 1775 ... 1776 ... {*assert 1777 ... date( "Ymd",DAT_Add( 2012,6,16,1 ) ) == '20120617' 1778 ... *} 1779 ... 1780 ... {*example 1781 ... echo '<p>',DAT_Add( 2012,5,12,4 ),'</p>'; //1337126400 1782 ... echo '<p>',date( 'Ymd',1337126400 ),'</p>'; //20120516 1783 ... *} 1784 ... 1785 ... *}} 1786 ... */ 1787 ... /* ====================================================================== */ 1788 ... function DAT_Add( $iYear,$iMonth,$iDay = 1,$iAdd = 1 ) 1789 ... /*--------------------------------------------------*/ 1790 ... { 1791 ... if ( is_int( $iYear ) ) /* If iYear passed as an int */ 1792 ... { 1793 ... } 1794 ... elseif ( is_string( $iYear ) && strlen( $iYear ) >= 8 ) /* If $iYear is a string (YYYYMMDD format expected) */ 1795 ... { 1796 ... $iAdd = $iMonth; /* Number of seconds to add is 2nd parameter */ 1797 ... 1798 ... $szDate = $iYear; /* The date we need to consider */ 1799 ... 1800 ... $iYear = (int) substr( $szDate,0,4 ); /* Extract $iYear */ 1801 ... $iMonth = (int) substr( $szDate,4,2 ); /* Extract $iMonth */ 1802 ... $iDay = (int) substr( $szDate,6,2 ); /* Extract $iDay */ 1803 ... } 1804 ... 1805 ... return ( mktime( 0,0,0,$iMonth,$iDay,$iYear ) + ( $iAdd * 86400 ) ); 1806 ... } /* End of function DAT_Add() */ 1807 ... /* ====================================================================== */ 1808 ... 1809 ... /* ====================================================================== */ 1810 ... /** {{*DAT_Diff( $aDate1,$aDate2 )= 1811 ... 1812 ... Time difference between 2 dates (only YYYYMMDD taken into consideration) 1813 ... 1814 ... {*params 1815 ... $aDate1 (array) An associative array with 'year','month','day' slots 1816 ... $aDate2 (array) An associative array with 'year','month','day' slots 1817 ... *} 1818 ... 1819 ... {*cdate 16/06/2012 14:18:13 *} 1820 ... {*version 5.0.0003 *} 1821 ... 1822 ... {*return 1823 ... (int) time difference in seconds (absolute value). -1 is 1824 ... returned in case of problem. 1825 ... *} 1826 ... 1827 ... {*assert 1828 ... DAT_Diff( DAT_2Array( '20120616' ),DAT_2Array( '20120617' ) ) == 86400 1829 ... *} 1830 ... 1831 ... {*example 1832 ... echo '<p>',DAT_Add( 2012,5,12,4 ),'</p>'; //1337126400 1833 ... echo '<p>',date( 'Ymd',1337126400 ),'</p>'; //20120516 1834 ... *} 1835 ... 1836 ... *}} 1837 ... 1838 ... */ 1839 ... /* ====================================================================== */ 1840 ... function DAT_Diff( $aDate1,$aDate2 ) 1841 ... /*--------------------------------*/ 1842 ... { 1843 ... $iRetVal = -1; /* Return value of the function */ 1844 ... 1845 ... if ( is_array( $aDate1 ) && is_array( $aDate2 ) ) /* If both dates are arrays */ 1846 ... { 1847 ... if ( ( isset( $aDate1['year'] ) && isset( $aDate1['month'] ) && isset( $aDate1['day'] ) ) && 1848 ... ( isset( $aDate2['year'] ) && isset( $aDate2['month'] ) && isset( $aDate2['day'] ) ) 1849 ... ) 1850 ... { 1851 ... $iDate1 = mktime( 0,0,0,(int) $aDate1['month'], 1852 ... (int) $aDate1['day'] , 1853 ... (int) $aDate1['year'] ); 1854 ... $iDate2 = mktime( 0,0,0,(int) $aDate2['month'], 1855 ... (int) $aDate2['day'] , 1856 ... (int) $aDate2['year'] ); 1857 ... $iRetVal = abs( $iDate2 - $iDate1 ); 1858 ... } /* if ( ( isset( $aDate1['year'] ) && ... */ 1859 ... } /* if ( is_array( $aDate1 ) && is_array( $aDate2 ) ) */ 1860 ... 1861 ... return ( $iRetVal ); /* Return result to caller */ 1862 ... } /* End of function DAT_Diff() */ 1863 ... /* ====================================================================== */ 1864 ... 1865 ... /* ====================================================================== */ 1866 ... /** {{*DAT_French( $iTime,$szFormat )= 1867 ... 1868 ... Returns the french representation of a date based on $iTime 1869 ... 1870 ... {*params 1871 ... $iTime (int) [c]time()[/c] representation 1872 ... $szFormat (string) Optional format of the output. 'm-d-Y' by default 1873 ... *} 1874 ... 1875 ... {*lupdate 16/06/2012 16:21:36 *} 1876 ... {*version 5.0.0003 *} 1877 ... 1878 ... {*return 1879 ... (string) Date representation (Sat 16 June 2012 is represented as '16-06-2012') 1880 ... *} 1881 ... 1882 ... {*assert 1883 ... DAT_French( 1339856589 ) == '16-06-2012' 1884 ... *} 1885 ... 1886 ... {*example 1887 ... echo DAT_French( 1339856589 ); // Prints '16-06-2012' 1888 ... echo DAT_French( 1339856589,'Y' ); // Prints '2012' 1889 ... echo DAT_French( 1339856589,'d-m-Y H:i:s' ); // Prints '16-06-2012 14:23:09' 1890 ... *} 1891 ... 1892 ... {*seealso 1893 ... DATTIME_French(), DAT_British(), DATTIME_British() 1894 ... *} 1895 ... *}} 1896 ... */ 1897 ... /* ====================================================================== */ 1898 ... function DAT_French( $iTime,$szFormat = 'd-m-Y' ) 1899 ... /*---------------------------------------------*/ 1900 ... { 1901 ... return ( date( $szFormat,$iTime ) ); 1902 ... } /* End of function DAT_French() */ 1903 ... /* ====================================================================== */ 1904 ... 1905 ... /* ====================================================================== */ 1906 ... /** {{*DATTIME_French( $iTime,$szFormat )= 1907 ... 1908 ... Returns the french representation of a date based on $iTime 1909 ... 1910 ... {*params 1911 ... $iTime (int) time() representation 1912 ... $szFormat (string) Optional format of the output. 'm-d-Y H:i:s' by default 1913 ... *} 1914 ... 1915 ... {*lupdate 16/06/2012 16:28:02 *} 1916 ... 1917 ... {*return 1918 ... (string) Date representation (Sat 16 June 2012, 16h28 59 sec 1919 ... is represented as '16-06-2012 16:28:59') 1920 ... *} 1921 ... 1922 ... {*assert 1923 ... DATTIME_French( 1339856589 ) === '16-06-2012 14:23:09' 1924 ... *} 1925 ... 1926 ... {*example 1927 ... echo DATTIME_French( 1339856589 ); // Prints '16-06-2012 14:23:09' 1928 ... *} 1929 ... 1930 ... {*seealso 1931 ... DAT_French(), DAT_British(), DATTIME_British() 1932 ... *} 1933 ... 1934 ... *}} 1935 ... 1936 ... */ 1937 ... /* ====================================================================== */ 1938 ... function DATTIME_French( $iTime,$szFormat = 'd-m-Y H:i:s' ) 1939 ... /*-------------------------------------------------------*/ 1940 ... { 1941 ... return ( date( $szFormat,$iTime ) ); 1942 ... } /* End of function DATTIME_French() */ 1943 ... /* ====================================================================== */ 1944 ... 1945 ... /* ====================================================================== */ 1946 ... /** {{*DAT_British( $iTime,$szFormat )= 1947 ... 1948 ... Returns the british representation of a date based on $iTime 1949 ... 1950 ... {*params 1951 ... $iTime (int) time() representation 1952 ... $szFormat (string) Optional format of the output. [c]'m/d/Y'[/c] by default 1953 ... *} 1954 ... 1955 ... {*lupdate 16/06/2012 16:34:05 *} 1956 ... {*version 5.0.0003 *} 1957 ... 1958 ... {*return 1959 ... (string) Date representation (Sat 16 June 2012 is represented as '16/06/2012') 1960 ... *} 1961 ... 1962 ... {*assert 1963 ... DAT_British( 1339856589 ) == '16/06/2012' 1964 ... *} 1965 ... 1966 ... {*example 1967 ... echo DAT_British( 1339856589 ); // Prints '16/06/2012' 1968 ... echo DAT_British( 1339856589,'Y' ); // Prints '2012' 1969 ... echo DAT_British( 1339856589,'d/m/Y H i s' ); // Prints '16/06/2012 14 23 09' 1970 ... *} 1971 ... 1972 ... {*seealso 1973 ... DATTIME_French(), DAT_French(), DATTIME_British() 1974 ... *} 1975 ... 1976 ... *}} 1977 ... */ 1978 ... /* ====================================================================== */ 1979 ... function DAT_British( $iTime,$szFormat = 'd/m/Y' ) 1980 ... /*----------------------------------------------*/ 1981 ... { 1982 ... return ( date( 'd/m/Y',$iTime ) ); 1983 ... } 1984 ... 1985 ... /* ====================================================================== */ 1986 ... /** {{*DATTIME_British( $iTime,$szFormat )= 1987 ... 1988 ... Returns the british representation of a date based on $iTime 1989 ... 1990 ... {*params 1991 ... $iTime (int) time() representation 1992 ... $szFormat (string) Optional format of the output. 'm-d-Y H:i:s' by default 1993 ... *} 1994 ... 1995 ... {*lupdate 16/06/2012 16:32:56 *} 1996 ... 1997 ... {*return 1998 ... (string) Date representation (Sat 16 June 2012, 16h28 59 sec is represented as '16/06/2012 16:28:59') 1999 ... *} 2000 ... 2001 ... {*assert 2002 ... DATTIME_British( 1339856589 ) === '16/06/2012 14:23:09' 2003 ... *} 2004 ... 2005 ... {*example 2006 ... echo DATTIME_British( 1339856589 ); // Prints '16/06/2012 14:23:09' 2007 ... *} 2008 ... 2009 ... {*seealso 2010 ... DATTIME_French(), DAT_French(), DAT_British() 2011 ... *} 2012 ... 2013 ... *}} 2014 ... */ 2015 ... /* ====================================================================== */ 2016 ... function DATTIME_British( $iTime,$szFormat = 'd/m/Y H:i:s' ) 2017 ... /*--------------------------------------------------------*/ 2018 ... { 2019 ... return ( date( 'd/m/Y H:i:s',$iTime ) ); 2020 ... } 2021 ... 2022 ... /* ====================================================================== */ 2023 ... /** {{*DAT_WeekNo( $szDate )= 2024 ... 2025 ... Returns the week number of year (ISO-8601 week number of year, weeks starting on Monday ) 2026 ... 2027 ... {*params 2028 ... $szDate (string) A date in the YYYYMMDD format 2029 ... *} 2030 ... 2031 ... {*lupdate 16/06/2012 14:18:13 *} 2032 ... {*version 5.0.0003 *} 2033 ... 2034 ... {*return 2035 ... (int) Week number 2036 ... *} 2037 ... 2038 ... {*assert 2039 ... DAT_WeekNo( '20120616') == 24 2040 ... *} 2041 ... 2042 ... {*example 2043 ... echo '<p>Week of the year: ',DAT_WeekNo( '20120616' ),'</p>'; // Week of the year: 24 2044 ... *} 2045 ... 2046 ... {*seealso 2047 ... DAT_Week2Date() 2048 ... *} 2049 ... 2050 ... *}} 2051 ... 2052 ... */ 2053 ... /* ====================================================================== */ 2054 ... function DAT_WeekNo( $szDate ) 2055 ... /*--------------------------*/ 2056 ... { 2057 ... $iDay = (int) substr( $szDate,6,2 ); 2058 ... $iMonth = (int) substr( $szDate,4,2 ); 2059 ... $iYear = (int) substr( $szDate,0,4 ); 2060 ... 2061 ... return ( date( "W",mktime( 0,0,0,$iMonth,$iDay,$iYear ) ) ); 2062 ... } 2063 ... 2064 ... /* ====================================================================== */ 2065 ... /** {{*DAT_Week2Date( $iWeek[,$iYear] )= 2066 ... 2067 ... Transforms a week number to the Monday date of that week 2068 ... 2069 ... {*params 2070 ... $iWeek (int) Week number 2071 ... $iYear (int) Year to consider. Optional. 2072 ... Default is current year 2073 ... *} 2074 ... 2075 ... {*cdate 02/01/2013 15:56:31 *} 2076 ... {*version 5.0.0011 *} 2077 ... 2078 ... {*return 2079 ... (int) Time value of the date ([c]time()[/c]) 2080 ... *} 2081 ... 2082 ... {*uses 2083 ... DAT_Boy() 2084 ... *} 2085 ... 2086 ... {*assert 2087 ... date( 'd/m/Y H:i:s',DAT_Week2Date( 14,2013 ) ) === '01/04/2013 00:00:00' 2088 ... *} 2089 ... 2090 ... {*assert 2091 ... date( 'd/m/Y H:i:s',DAT_Week2Date( 14,2014 ) ) === '31/03/2014 00:00:00' 2092 ... *} 2093 ... 2094 ... {*exec 2095 ... echo '<p>Week 14 of 2013 starts on ' . date('d/m/Y',DAT_Week2Date( 14,2013 ) ) . '</p>'; 2096 ... echo '<p>Week 14 of 2014 starts on ' . date('d/m/Y',DAT_Week2Date( 14,2014 ) ) . '</p>'; 2097 ... *} 2098 ... 2099 ... {*seealso 2100 ... DAT_WeekNo(), DAT_Sow(), DAT_Eow() 2101 ... *} 2102 ... 2103 ... *}} 2104 ... */ 2105 ... /* ====================================================================== */ 2106 ... function DAT_Week2Date( $iWeek,$iYear = null ) 2107 ... /*------------------------------------------*/ 2108 ... { 2109 ... $iDays = $iWeek * 7; /* Day count since beginning of the year (not exact match) */ 2110 ... 2111 ... if ( is_null( $iYear ) ) /* If parameter not passed */ 2112 ... { 2113 ... $iYear = (int) date('Y'); 2114 ... } 2115 ... 2116 ... $iStart = DAT_Boy( $iYear) ; /* BOY (Beginning of the year) */ 2117 ... $iDayOfTheWeek = $iStart + ( $iDays * 86400 ); /* Week # should be somewhere around that date */ 2118 ... $iNowWeek = date( 'W',$iDayOfTheWeek ); /* Now, we should be very close to Week # */ 2119 ... 2120 ... if ( $iNowWeek > $iWeek ) /* If $iNowWeek is bigger than Week # */ 2121 ... { 2122 ... $iDayOfTheWeek -= 5 * 86400; /* Let's move backward by 5 days */ 2123 ... } 2124 ... elseif ( $iNowWeek < $iWeek ) /* If $iNowWeek is less than Week # */ 2125 ... { 2126 ... $iDayOfTheWeek += 5 * 86400; /* Let's move forward by 5 days */ 2127 ... } 2128 ... 2129 ... $iDayIndex = date( 'w',$iDayOfTheWeek ); /* What's that day? A Wednesday? A Thursday? ... */ 2130 ... 2131 ... if ( $iDayIndex != 0 ) /* If not a Sunday */ 2132 ... { 2133 ... $iResult = $iDayOfTheWeek - ( ( $iDayIndex - 1 ) * 86400 ); /* This should be the date of the Monday in that week */ 2134 ... } 2135 ... else 2136 ... { 2137 ... $iResult = $iDayOfTheWeek + 86400; /* If a Sunday ... then we need to move to the enxt Monday */ 2138 ... } 2139 ... 2140 ... return ( $iResult ); /* Return result to caller */ 2141 ... } /* End of function DAT_Week2Date() ================================== */ 2142 ... 2143 ... /* ====================================================================== */ 2144 ... /** {{*TIM_2Array( $szTime,$szPart )= 2145 ... 2146 ... Turns a time (HH[:]mm[:]SS) into an associative array 2147 ... 2148 ... {*params 2149 ... $szDate (string) A HH[:]mm[:]SS] time string 2150 ... $szPart (string) Optional parameter: the part to be returned[br] 2151 ... - [c]'hour'[/c] : return the hour part as a string[br] 2152 ... - [c]'min' [/c] : return the min part as a string[br] 2153 ... - [c]'sec' [/c] : return the sec part as a string[br] 2154 ... *} 2155 ... 2156 ... {*cdate 16/06/2012 16:41:18 *} 2157 ... {*version 5.0.0003 *} 2158 ... 2159 ... {*return 2160 ... (mixed) string if $szPart is passed; array if $szPart is not mentioned 2161 ... *} 2162 ... 2163 ... {*assert 2164 ... TIM_2Array( '23:50:59','hour' ) == '23' 2165 ... *} 2166 ... 2167 ... {*assert 2168 ... TIM_2Array( '23:50:59','min' ) == '50' 2169 ... *} 2170 ... 2171 ... {*assert 2172 ... TIM_2Array( '23:50:59','sec' ) == '59' 2173 ... *} 2174 ... 2175 ... {*assert 2176 ... STR_Empty( TIM_2Array( '23:50','sec' ) ) == true 2177 ... *} 2178 ... 2179 ... {*example 2180 ... Example #1 2181 ... echo TIM_2Array( '23:50:59','hour' ); // '23' 2182 ... 2183 ... Example #2 2184 ... echo TIM_2Array( '23:50:59','min' ); // '50' 2185 ... 2186 ... Example #3 2187 ... echo TIM_2Array( '23:50:59','sec' ); // '59' 2188 ... 2189 ... Example #3 2190 ... var_dump( TIM_2Array( '14:09:59' ) ); 2191 ... *} 2192 ... *}} 2193 ... */ 2194 ... /* ====================================================================== */ 2195 ... function TIM_2Array( $szTime,$szPart = null ) 2196 ... /*-----------------------------------------*/ 2197 ... { 2198 ... $aParts = array(); /* Return value of the function */ 2199 ... 2200 ... $aParts['sec'] = /* Prepare associative array */ 2201 ... $aParts['min'] = 2202 ... $aParts['hour'] = 2203 ... ''; 2204 ... 2205 ... if ( preg_match( '/(?P<hour>0[0-9]|1[0-9]|2[0-3])(:??(?P<min>0[0-9]|[0-5][0-9])(:??(?P<sec>0[0-9]|[0-5][0-9]))?)?/',$szTime,$aMatch ) ) 2206 ... //if ( preg_match( '/(?P<hour>\d{1,2})(:{0,1}(?P<min>\d{1,2})(:{0,1}(?P<sec>\d{1,2}))?)?/',$szTime,$aMatch ) ) 2207 ... { 2208 ... if ( isset( $aMatch['hour'] ) ) 2209 ... $aParts['hour'] = $aMatch['hour']; /* Hours */ 2210 ... if ( isset( $aMatch['min'] ) ) 2211 ... $aParts['min'] = $aMatch['min']; /* Minutes*/ 2212 ... if ( isset( $aMatch['sec'] ) ) 2213 ... $aParts['sec'] = $aMatch['sec']; /* Seconds */ 2214 ... } 2215 ... 2216 ... if ( ! is_null( $szPart ) && isset( $aParts[$szPart] ) ) 2217 ... { 2218 ... return ( $aParts[$szPart] ); /* Return part that is requested */ 2219 ... } 2220 ... else 2221 ... { 2222 ... return ( $aParts ); /* Return result to caller */ 2223 ... } 2224 ... } /* End of function TIM_2Array() ===================================== */ 2225 ... 2226 ... /* ====================================================================== */ 2227 ... /** {{*DAT_2Array( $szDate,$szPart )= 2228 ... 2229 ... Turns a date ([c]YYYYMMDD[HHmmSS][/c]) into an associative array 2230 ... 2231 ... {*params 2232 ... $szDate (mixed) A YYYYMMDD[HHmmSS] date string. If an integer is 2233 ... supplied, then it is considered as a [c]time()[/c] 2234 ... value on which a [c]date('YmdHis')[/c] is applied 2235 ... $szPart (string) Optional parameter: the part to be returned:[br] 2236 ... - 'year' : return the year part as a string[br] 2237 ... - 'month' : return the month part as a string[br] 2238 ... - 'day' : return the day part as a string[br] 2239 ... - 'time' : return the time part as a string[br] 2240 ... *} 2241 ... 2242 ... {*cdate 16/06/2012 14:14:03 *} 2243 ... {*version 5.0.0003 *} 2244 ... 2245 ... {*return 2246 ... (mixed) string if $szPart is passed; array if $szPart is not mentioned 2247 ... *} 2248 ... 2249 ... {*assert 2250 ... DAT_2Array( '20120616140959','year' ) == '2012' 2251 ... *} 2252 ... 2253 ... {*assert 2254 ... DAT_2Array( '20120616140959','month' ) == '06' 2255 ... *} 2256 ... 2257 ... {*assert 2258 ... DAT_2Array( '20120616140959','day' ) == '16' 2259 ... *} 2260 ... 2261 ... {*assert 2262 ... DAT_2Array( '20120616140959','time' ) == '140959' 2263 ... *} 2264 ... 2265 ... {*assert 2266 ... DAT_2Array( '201206161410','time' ) == '1410' 2267 ... *} 2268 ... 2269 ... {*example 2270 ... Example #1 2271 ... echo DAT_2Array( '20120616140959','time' ); // '140959' 2272 ... 2273 ... Example #2 2274 ... var_dump( DAT_2Array( '20120616140959' ) ); 2275 ... 2276 ... Example #3 2277 ... var_dump( DAT_2Array( STR_dionly( '2012-06-16 14:09:59' ) ) ); 2278 ... *} 2279 ... 2280 ... {*seealso 2281 ... DAT_Split() 2282 ... *} 2283 ... *}} 2284 ... */ 2285 ... /* ====================================================================== */ 2286 ... function DAT_2Array( $szDate,$szPart = null ) 2287 ... /*-----------------------------------------*/ 2288 ... { 2289 ... $aParts = array(); /* Return value of the function */ 2290 ... 2291 ... $aParts['time'] = /* Prepare associative array */ 2292 ... $aParts['day'] = 2293 ... $aParts['month'] = 2294 ... $aParts['year'] = 2295 ... null; 2296 ... 2297 ... if ( is_int( $szDate ) ) 2298 ... { 2299 ... $szDate = date( 'YmdHis',$szDate ); 2300 ... } 2301 ... 2302 ... if ( preg_match( '%(?P<year>(19|20)[0-9]{2})[- /.]{0,1}(?P<month>(0[1-9]|1[012]))[- /.]{0,1}(?P<day>(0[1-9]|[12][0-9]|3[01]))(?P<time>\d{0,6})?%',$szDate,$aMatch ) ) 2303 ... { 2304 ... if ( isset( $aMatch['year'] ) ) 2305 ... $aParts['year'] = $aMatch['year']; /* Year */ 2306 ... if ( isset( $aMatch['month'] ) ) 2307 ... $aParts['month'] = $aMatch['month']; /* Month */ 2308 ... if ( isset( $aMatch['day'] ) ) 2309 ... $aParts['day'] = $aMatch['day']; /* Year */ 2310 ... if ( isset( $aMatch['time'] ) ) 2311 ... $aParts['time'] = $aMatch['time']; /* Time */ 2312 ... } 2313 ... 2314 ... if ( ! is_null( $szPart ) && isset( $aParts[$szPart] ) ) 2315 ... { 2316 ... return ( $aParts[$szPart] ); /* Return part that is requested */ 2317 ... } /* if ( ! is_null( $szPart ) && isset( $aParts[$szPart] ) ) */ 2318 ... else 2319 ... { 2320 ... return ( $aParts ); /* Return result to caller */ 2321 ... } 2322 ... } /* End of function DAT_2Array() ===================================== */ 2323 ... 2324 ... /* ====================================================================== */ 2325 ... /** {{*DAT_NextMonth( $month,$year,$n,$nMonth,$nYear )= 2326 ... 2327 ... Determines the next month of a date (n added or substracted) 2328 ... 2329 ... {*params 2330 ... $month (int) Starting month 2331 ... $year (int) Starting year 2332 ... $n (int) Number of months to jump (can be negative) 2333 ... $nMonth (int) By reference. Resulting month 2334 ... $nYear (int) By reference. Resulting year 2335 ... *} 2336 ... 2337 ... {*return 2338 ... (void) 2339 ... *} 2340 ... 2341 ... {*exec 2342 ... $iMonth = 2343 ... $iYear = -1; 2344 ... 2345 ... DAT_NextMonth( 12,2012,-13,$iMonth,$iYear ); 2346 ... echo '<p>',$iMonth,'/',$iYear,'</p>'; // 11/2011 2347 ... 2348 ... echo LSUnitTesting::assert( $iMonth === 11 && $iYear === 2011 , 2349 ... 'ASSERTION SUCCESSFUL: month and year correctly determined' , 2350 ... 'ASSERTION FAILURE: incorrect month and/or year' , 2351 ... 'GuideAssert' ); 2352 ... 2353 ... DAT_NextMonth( 12,2012,1,$iMonth,$iYear ); 2354 ... echo '<p>',$iMonth,'/',$iYear,'</p>'; // 1/2013 2355 ... 2356 ... echo LSUnitTesting::assert( $iMonth === 1 && $iYear === 2013 , 2357 ... 'ASSERTION SUCCESSFUL: month and year correctly determined' , 2358 ... 'ASSERTION FAILURE: incorrect month and/or year' , 2359 ... 'GuideAssert' ); 2360 ... *} 2361 ... 2362 ... *}} 2363 ... */ 2364 ... /* ====================================================================== */ 2365 ... function DAT_NextMonth( $month,$year,$n,&$nMonth,&$nYear ) 2366 ... /*------------------------------------------------------*/ 2367 ... { 2368 ... $NewMonth = $month + $n; /* This is the month we are going to */ 2369 ... 2370 ... if ( $NewMonth > 12 ) /* Passed December ? */ 2371 ... { 2372 ... $nMonth = $NewMonth % 12; /* Modulo 12 */ 2373 ... $nYear = $year + 1; /* Increment year by 1 */ 2374 ... } 2375 ... else if ( $NewMonth < 1 ) /* Negative month */ 2376 ... { 2377 ... $nMonth = 12 + ( $NewMonth % 12 ); /* Modulo 12 ... + 12 to get back on our feet (e.g. Nov is -1 ... +12 = 11) */ 2378 ... $nYear = $year - 1; /* Decrement year */ 2379 ... } /* else if ( $NewMonth < 1 ) */ 2380 ... else /* else of ... if ( $NewMonth < 1 ) */ /* This is just the normal case */ 2381 ... { 2382 ... $nMonth = $NewMonth; /* Month is set */ 2383 ... $nYear = $year; /* Year is set */ 2384 ... } /* End of ... else of ... if ( $NewMonth < 1 ) */ 2385 ... } /* End of function DAT_NextMonth() ================================== */ 2386 ... 2387 ... /* ====================================================================== */ 2388 ... /** {{*DAT_Eom( $iMonth,$iYear )= 2389 ... 2390 ... Returns the day that is the end of the month 2391 ... 2392 ... {*params 2393 ... $iMonth (int) Optional month to consider. Current month by default. 2394 ... $iYear (int) Optional year to consider. Current year by default. 2395 ... *} 2396 ... 2397 ... {*return 2398 ... (int) The day that is the last day of the month 2399 ... *} 2400 ... 2401 ... {*cdate 17/03/2013 18:42 *} 2402 ... {*version 5.1.0001 *} 2403 ... 2404 ... {*assert 2405 ... DAT_Eom( 1 ) === 31 2406 ... *} 2407 ... 2408 ... {*assert 2409 ... DAT_Eom( 2,2012 ) === 29 2410 ... *} 2411 ... 2412 ... {*assert 2413 ... DAT_Eom( 2,2013 ) === 28 2414 ... *} 2415 ... 2416 ... {*assert 2417 ... DAT_Eom( 3 ) === 31 2418 ... *} 2419 ... 2420 ... {*assert 2421 ... DAT_Eom( 4 ) === 30 2422 ... *} 2423 ... 2424 ... {*assert 2425 ... DAT_Eom( 12 ) === 31 2426 ... *} 2427 ... 2428 ... *}} 2429 ... */ 2430 ... /* ====================================================================== */ 2431 ... function DAT_Eom( $iMonth = null,$iYear = null ) 2432 ... /*--------------------------------------------*/ 2433 ... { 2434 ... $iFebDays = 28; 2435 ... 2436 ... if ( is_null( $iYear ) ) 2437 ... { 2438 ... $iYear = (int) date( 'Y' ); 2439 ... } 2440 ... 2441 ... if ( is_null( $iMonth ) ) 2442 ... { 2443 ... $iMonth = (int) date( 'm' ); 2444 ... } 2445 ... 2446 ... /* Find out is we are dealing with a leap year or not */ 2447 ... if ( $iYear % 4 == 0 && $iYear % 100 != 0 || $iYear % 400 == 0 ) 2448 ... { 2449 ... $iFebDays = 29; 2450 ... } 2451 ... 2452 ... /* Preparing number of days per month */ 2453 ... $aDays = array( 1 => 31,$iFebDays,31,30,31,30,31,31,30,31,30,31 ); 2454 ... 2455 ... return ( $aDays[$iMonth] ); 2456 ... } 2457 ... 2458 ... /* ================================================================== */ 2459 ... /* .......................................................................... 2460 ... Function : DAT_Calendar() 2461 ... Purpose : Draws a calendar in a table 2462 ... Parameters : year ... the year the calendar should show 2463 ... month ... the month the calendar should show 2464 ... cal_class ... the CSS class assigned to the calendar 2465 ... summary ... the summary that is attached to the <table> 2466 ... tag (WACG compliance) 2467 ... lang ... the language of the calendar (fr,en,nl) 2468 ... keyword ... a keyword attached to the calendar. Later on 2469 ... this keyword is passed to your callback 2470 ... function (if any) 2471 ... callback ... the name of a callback function that is called 2472 ... for every date pertaining to the current month 2473 ... the function is drwaing 2474 ... date_min ... the lower range of the calendar : we won't 2475 ... provide links for dates that are older than 2476 ... this limit (YYYYMMDD format). 2477 ... date_max ... the upper range of the calendar : we won't 2478 ... provide links for dates that are more recent 2479 ... than this limit (YYYYMMDD format). 2480 ... Return : Null 2481 ... TODO : This function will replace DrawCalendar() which is to be 2482 ... considered as obsolete 2483 ... .......................................................................... */ 2484 ... function DAT_Calendar( $year,$month,$day, 2485 ... $cal_class = '', 2486 ... $lang = 'fr',$summary = 'Calendrier',$keyword = '', 2487 ... $callback = null,$date_min = null,$date_max = null ) 2488 ... /*-----------------------------------------------------------------------*/ 2489 ... { 2490 ... /******************************************************************/ 2491 ... /* Some words about the callback function: */ 2492 ... /* */ 2493 ... /* A calendar function must be so generic that it can be called */ 2494 ... /* in a lot of different instances: for example to display news, */ 2495 ... /* to display activities, to be used in a blog, etc. */ 2496 ... /* */ 2497 ... /* With that in mind, you quickly realize that the calendar */ 2498 ... /* function cannot be parameterized to a level like the one */ 2499 ... /* needed to face all kind of situations. For example, one may */ 2500 ... /* want the function to render some days of the calendar in bold */ 2501 ... /* in case these dates are holidays, another will want dates in */ 2502 ... /* bold if they are things connected to a date (for example if */ 2503 ... /* news are available at that specific date) ... and even to be */ 2504 ... /* able to link to a given page if that's the case. */ 2505 ... /* */ 2506 ... /* Because of all this, we have decided to let the user do what */ 2507 ... /* he wants by providing a callback mechanism : for each date */ 2508 ... /* of the calendar, we will branch the excution to this callback */ 2509 ... /* function IF provided. This let's people choose what works */ 2510 ... /* better for them. */ 2511 ... /* */ 2512 ... /* This is what the $callback function is all about. We have even */ 2513 ... /* provided the $theCallback variable that will be set to */ 2514 ... /* $callback if the latter is found (function_exists()). */ 2515 ... /* */ 2516 ... /* */ 2517 ... /* */ 2518 ... /* Some other words about the design of the calendar: */ 2519 ... /* */ 2520 ... /* 1) the calendar is rendered as a table */ 2521 ... /* 2) the way the table is presented should be entirely driven */ 2522 ... /* by CSS (no style is given) */ 2523 ... /* */ 2524 ... /******************************************************************/ 2525 ... 2526 ... $theCallback = null; /* Callback function we need to call (none by default) */ 2527 ... 2528 ... if ( $callback != null ) /* If parameter sent */ 2529 ... { 2530 ... $theCallback = function_exists( $callback ) ? $callback : null;/* Set callback to null if function not found */ 2531 ... } /* if ( $callback != null ) */ 2532 ... 2533 ... if ( $lang == null ) /* If language NOT passed */ 2534 ... { 2535 ... $lang = 'fr'; /* Use French by default */ 2536 ... } /* if ( $lang == null ) */ 2537 ... 2538 ... $lang = strtolower( $lang ); /* Turn language to lower case */ 2539 ... 2540 ... if ( $summary == null ) /* If summary NOT provided */ 2541 ... { 2542 ... switch ( $lang ) /* Build summary in function of the language */ 2543 ... { 2544 ... case "en" : $summary = "Calandar (7 columns - 6 rows : 1 column per day)"; break; 2545 ... case "nl" : $summary = "Kalender (7 columns - 6 rows : 1 column per day)"; break; 2546 ... default : $summary = "Calendrier (7 colonnes - 6 lignes : 1 colonne par jour)";break; 2547 ... } /* switch ( $lang ) */ 2548 ... } /* if ( $summary == null ) */ 2549 ... 2550 ... if ( $cal_class == null ) /* If the calendar has NOT been passed a class */ 2551 ... { 2552 ... $cal_class = "LS_VAESOLI_CALENDAR"; /* This is the default class assigned to the table */ 2553 ... } /* if ( $cal_class == null ) */ 2554 ... 2555 ... switch ( $lang ) /* Build month and day arrays in function of the language */ 2556 ... { 2557 ... /* {*todo Use DAT_aDaysAndMonths() *} */ 2558 ... /* -- English --------------------------------------------------------------------------------------------------------- */ 2559 ... case "en" : $aMonths = array( array( "January" ,"February" ,"March" ,"April" ,"May" ,"June" , 2560 ... "July" ,"August" ,"September","October" ,"November" ,"December"), 2561 ... array( "Jan" ,"Feb" ,"Mar" ,"Apr" ,"May" ,"Jun" , 2562 ... "Jul" ,"Aug" ,"Sep" ,"Oct" ,"Nov" ,"Dec" ) ); 2563 ... $aDays = array( array( "Monday" ,"Tuesday" ,"Wednesday","Thursday" ,"Friday" ,"Saturday" ,"Sunday"), 2564 ... array( "Mo" ,"Tu" ,"We" ,"Th" ,"Fr" ,"Sa" ,"Su" ) ); 2565 ... break; 2566 ... /* -- Dutch ----------------------------------------------------------------------------------------------------------- */ 2567 ... case "nl" : $aMonths = array( array( "Januari" ,"Februari" ,"Maart" ,"April" ,"Mei" ,"Juni" , 2568 ... "Juli" ,"Augustus" ,"September","Oktober" ,"November" ,"December"), 2569 ... array( "Janu" ,"Feb" ,"Maa" ,"Apr" ,"Mei" ,"Jun" , 2570 ... "Jul" ,"Aug" ,"Sep" ,"Okt" ,"Nov" ,"Dec" ) ); 2571 ... $aDays = array( array( "Maandag" ,"Dinsdag" ,"Woensdag" ,"Donderdag","Vrijdag" ,"Zaterdag","Zondag"), 2572 ... array( "Ma" ,"Di" ,"Wo" ,"Do" ,"Vr" ,"Za" ,"Zo" ) ); 2573 ... break; 2574 ... /* -- French ---------------------------------------------------------------------------------------------------------- */ 2575 ... default : $aMonths = array( array( "Janvier" ,"Février" ,"Mars" ,"Avril" ,"Mai" ,"Juin" , 2576 ... "Juillet" ,"Août" ,"Septembre","Octobre" ,"Novembre" ,"Décembre"), 2577 ... array( "Jan" ,"Fév" ,"Mar" ,"Avr" ,"Mai" ,"Jun" , 2578 ... "Jul" ,"Aoû" ,"Sep" ,"Oct" ,"Nov" ,"Déc" ) ); 2579 ... $aDays = array( array( "Lundi" ,"Mardi" ,"Mercredi" ,"Jeudi" ,"Vendredi" ,"Samedi","Dimanche"), 2580 ... array( "Lu" ,"Ma" ,"Me" ,"Je" ,"Ve" ,"Sa" ,"Di" ) ); 2581 ... break; 2582 ... } /* switch ( $lang ) */ 2583 ... 2584 ... $szMo = $aDays[1][0]; $szMonday = $aDays[0][0]; /* Monday */ 2585 ... $szTu = $aDays[1][1]; $szTuesday = $aDays[0][1]; /* Tuesday */ 2586 ... $szWe = $aDays[1][2]; $szWednesday = $aDays[0][2]; /* Wednesday */ 2587 ... $szTh = $aDays[1][3]; $szThursday = $aDays[0][3]; /* Thursday */ 2588 ... $szFr = $aDays[1][4]; $szFriday = $aDays[0][4]; /* Friday */ 2589 ... $szSa = $aDays[1][5]; $szSaturday = $aDays[0][5]; /* Saturday */ 2590 ... $szSu = $aDays[1][6]; $szSunday = $aDays[0][6]; /* Sunday */ 2591 ... 2592 ... /* This is an array with all possible dates in the calendar: 2593 ... 2594 ... +---------+--------------+---------+ 2595 ... | < | September 05 | > | 2596 ... +----+----+----+----+----+----+----+ 2597 ... | Mo | Tu | We | Th | Fr | Sa | Su | 2598 ... +----+----+----+----+----+----+----+ 2599 ... | | | | | | | | Row 1 2600 ... +----+----+----+----+----+----+----+ 2601 ... | | | | | | | | Row 2 2602 ... +----+----+----+----+----+----+----+ 2603 ... | | | | | | | | Row 3 2604 ... +----+----+----+----+----+----+----+ 2605 ... | | | | | | | | Row 4 2606 ... +----+----+----+----+----+----+----+ 2607 ... | | | | | | | | Row 5 2608 ... +----+----+----+----+----+----+----+ 2609 ... | | | | | | | | Row 6 2610 ... +----+----+----+----+----+----+----+ 2611 ... 2612 ... Given 6 rows, there are 42 cells in the calendar and this 2613 ... is precisely what the array that follows is all about: 2614 ... */ 2615 ... 2616 ... $e_cell = "<td class=\"empty\"> </td>"; /* This is how an empty cell is represented in the table */ 2617 ... 2618 ... $aCal = array( 1 => $e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell, 2619 ... $e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell, 2620 ... $e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell, 2621 ... $e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell, 2622 ... $e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell, 2623 ... $e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell ); 2624 ... 2625 ... /* Here, we need to know few things about the calendar we're about to display: 2626 ... 2627 ... If we imagine that we're the 4th of September 2005, then we need to know : 2628 ... 2629 ... 1) How many days we have in September 2005 : 30 ($NumberOfDays) 2630 ... 2) What day of the week was the 1st of September 2005 : 2631 ... 4 ... Thursday (0 ... for Sunday, 6 ... for Saturday) 2632 ... ($DayOfTheWeekBOM) 2633 ... 3) What date are we TODAY (day of the month) ($TodayDay) 2634 ... */ 2635 ... 2636 ... $NumberOfDays = date( "t",mktime( 0,0,0,$month,1,$year ) ); /* Number of days in this month */ 2637 ... $DayOfTheWeekBOM = date( "w",mktime( 0,0,0,$month,1,$year ) ); /* What day the 1st of the month was */ 2638 ... $TodayYear = (int) date( "Y" ); /* What year are we today */ 2639 ... $TodayMonth = (int) date( "m" ); /* What month are we today */ 2640 ... $TodayDay = (int) date( "d" ); /* What day are we today */ 2641 ... 2642 ... 2643 ... $DayOfTheWeekBOM = $DayOfTheWeekBOM == 0 ? 7 : $DayOfTheWeekBOM; /* If Sunday ... turn this to 7 instead of 0 */ 2644 ... 2645 ... $szMonth = $aMonths[0][$month-1] . " $year"; /* Form a string similar to "Septembre 2005" */ 2646 ... 2647 ... /* ****************************************************** 2648 ... We need to create 2 links : one to the previous month 2649 ... one to the next month 2650 ... That's what we will be constructing now BUT in case 2651 ... a callback function is provided, then our construction 2652 ... may be invalidated by the callback 2653 ... ***************************************************** */ 2654 ... $nMonth = $month; /* Initialize this variable nMonth */ 2655 ... $nYear = $year; /* Initialize this variable nYear */ 2656 ... 2657 ... DAT_NextMonth( $month,$year,-1,$nMonth,$nYear ); /* Previous month (DAT_NextMonth() with -1) */ 2658 ... 2659 ... $nPreviousMonth = $nMonth; /* Remember the value of the previous month (for callback function) */ 2660 ... $nPreviousYear = $nYear; /* Remember the value of the previous year (for callback function) */ 2661 ... 2662 ... $szMinus = ''; /* No link to a previous date by default */ 2663 ... 2664 ... // ALL THIS SHOULD COME FROM DICTIONARY 2665 ... switch ( $lang ) /* Title in function of languag */ 2666 ... { 2667 ... /* -- English ------------------------------------------------------------------------------------------------------ */ 2668 ... case "en" : $szTitle = 'Previous month'; break; 2669 ... /* -- Dutch -------------------------------------------------------------------------------------------------------- */ 2670 ... case "nl" : $szTitle = 'Vorige maand' ; break; 2671 ... default : $szTitle = 'Mois précédent'; break; 2672 ... } 2673 ... 2674 ... if ( ! is_null( $date_min ) ) /* If a lower range has been set */ 2675 ... { 2676 ... $year_min = (int) substr( $date_min,0,4 ); /* Extract year of lower range */ 2677 ... $month_min = (int) substr( $date_min,4,2 ); /* Extract month of lower range */ 2678 ... 2679 ... if ( $year_min < $nPreviousYear ) /* If previous year still in acceptable range */ 2680 ... { 2681 ... $szMinus = "<a href=\"$nYear/$nMonth/$TodayDay\" title=\"{$szTitle}\"><</a>"; 2682 ... } /* if ( $year_min < $nPreviousYear ) */ 2683 ... elseif ( $year_min == $nPreviousYear ) 2684 ... { 2685 ... if ( $month_min <= $nPreviousMonth ) 2686 ... { 2687 ... $szMinus = "<a href=\"$nYear/$nMonth/$TodayDay\" title=\"{$szTitle}\"><</a>"; 2688 ... } 2689 ... } /* End of ... elseif ( $year_min == $nPreviousYear ) */ 2690 ... } 2691 ... else 2692 ... { 2693 ... $szMinus = "<a href=\"$nYear/$nMonth/$TodayDay\" title=\"{$szTitle}\"><</a>"; 2694 ... } 2695 ... 2696 ... DAT_NextMonth( $month,$year,1,$nMonth,$nYear ); /* Next month */ 2697 ... 2698 ... $nNextMonth = $nMonth; /* Remember the value of next month (for callback function) */ 2699 ... $nNextYear = $nYear; /* Remember the value of next year (for callback function) */ 2700 ... 2701 ... $szPlus = ''; /* No link to a future date by default */ 2702 ... 2703 ... // ALL THIS SHOULD COME FROM DICTIONARY 2704 ... switch ( $lang ) /* Title in function of languag */ 2705 ... { 2706 ... /* -- English ------------------------------------------------------------------------------------------------------ */ 2707 ... case "en" : $szTitle = 'Next month'; break; 2708 ... /* -- Dutch -------------------------------------------------------------------------------------------------------- */ 2709 ... case "nl" : $szTitle = 'Volgende maand' ; break; 2710 ... default : $szTitle = 'Mois suivant'; break; 2711 ... } 2712 ... 2713 ... if ( ! is_null( $date_max ) ) /* If a lower range has been set */ 2714 ... { 2715 ... $year_max = (int) substr( $date_max,0,4 ); /* Extract year */ 2716 ... $month_max = (int) substr( $date_max,4,2 ); /* Extract month */ 2717 ... 2718 ... if ( $year_max > $nNextYear ) 2719 ... { 2720 ... $szPlus = "<a href=\"$nYear/$nMonth/$TodayDay\" title=\"{$szTitle}\">></a>"; 2721 ... } /* if ( $year_max > $nNextYear ) */ 2722 ... elseif ( $year_max == $nNextYear ) 2723 ... { 2724 ... if ( $month_max >= $nNextMonth ) 2725 ... { 2726 ... $szPlus = "<a href=\"$nYear/$nMonth/$TodayDay\" title=\"{$szTitle}\">></a>"; 2727 ... } 2728 ... } /* End of ... elseif ( $year_max == $nNextYear ) */ 2729 ... } 2730 ... else 2731 ... { 2732 ... $szPlus = "<a href=\"$nYear/$nMonth/$TodayDay\" title=\"{$szTitle}\">></a>"; 2733 ... } 2734 ... 2735 ... /* OF ... we have done our best : we have provided a link for 2736 ... the previous month and a link to the next month. But as we 2737 ... have said, this can be overruled by the callback function 2738 ... the user has provided. Let's play the game ! 2739 ... */ 2740 ... 2741 ... if ( $theCallback != null ) /* If callback provided */ 2742 ... { 2743 ... $szCell = $theCallback( "PREVIOUS" , /* Type of operation */ 2744 ... $keyword , /* Keyword as it was passed to us */ 2745 ... $lang , /* The language we are operating in */ 2746 ... $szMinus , /* The value of the previous link as we have created */ 2747 ... $year,$month,$day , /* Year, month and day as passed in the URL */ 2748 ... $NumberOfDays , /* Number of days in this month */ 2749 ... $TodayYear,$TodayMonth,$TodayDay, /* Today (year, month, day) */ 2750 ... 0,0 , /* Cell position,day rendered in the cell (here N/A => 0) */ 2751 ... $nPreviousMonth,$nPreviousYear , /* Previous month, previous year */ 2752 ... $nNextMonth,$nNextYear , /* Next month, next year */ 2753 ... $date_min,$date_max ); /* Date range */ 2754 ... 2755 ... if ( $szCell ) 2756 ... $szMinus = $szCell; 2757 ... 2758 ... $szCell = $theCallback( "NEXT" , /* Type of operation */ 2759 ... $keyword , /* Keyword as it was passed to us */ 2760 ... $lang , /* The language we are operating in */ 2761 ... $szPlus , /* The value of the next link as we have created */ 2762 ... $year,$month,$day , /* Year, month and day as passed in the URL */ 2763 ... $NumberOfDays , /* Number of days in this month */ 2764 ... $TodayYear,$TodayMonth,$TodayDay, /* Today (year, month, day) */ 2765 ... 0,0 , /* Cell position,day rendered in the cell (here N/A => 0) */ 2766 ... $nPreviousMonth,$nPreviousYear , /* Previous month, previous year */ 2767 ... $nNextMonth,$nNextYear , /* Next month, next year */ 2768 ... $date_min,$date_max ); /* Date range */ 2769 ... 2770 ... if ( $szCell ) 2771 ... $szPlus = $szCell; 2772 ... } /* if ( $theCallback != null ) */ 2773 ... 2774 ... 2775 ... /* Let's now populate the 42 cells (6 rows of 7 days) with the 2776 ... days corresponding to this month */ 2777 ... 2778 ... $bBeforeLastRowVisible = true; 2779 ... $bLastRowVisible = true; 2780 ... $n = 1; 2781 ... 2782 ... /* for ( $i = $DayOfTheWeekBOM;( ( $i<=count($aCal) ) && ( $n <= $NumberOfDays ) );$i++ ) */ 2783 ... for ( $i = $DayOfTheWeekBOM;( $i<=count($aCal) );$i++ ) 2784 ... { 2785 ... if ( $n > $NumberOfDays ) /* If this date falls off the calendar */ 2786 ... { 2787 ... if ( $i === 29 ) /* And if we are in the before last row of the calendar */ 2788 ... { 2789 ... $bBeforeLastRowVisible = $bLastRowVisible = false; 2790 ... } 2791 ... else if ( $i === 36 ) /* And if we are in the last row of the calendar */ 2792 ... { 2793 ... $bLastRowVisible = false; 2794 ... } 2795 ... 2796 ... $aCal[$i] = "<td class=\"falloff\"> </td>"; /* Render this date as an empty date (provide CSS for it!) */ 2797 ... 2798 ... } /* if ( $n > $NumberOfDays ) */ 2799 ... else /* Else of ... if ( $n > $NumberOfDays ) */ /* This date is within our acceptable range of dates */ 2800 ... { 2801 ... if ( ( $year === $TodayYear ) && /* If this is TODAY (now) */ 2802 ... ( $month === $TodayMonth ) && 2803 ... ( $n === $TodayDay ) ) 2804 ... { 2805 ... $aCal[$i] = "<td class=\"today\">{$n}</td>"; /* Mark it as today */ 2806 ... } /* if ( ( $year === $TodayYear ) && ... */ 2807 ... else /* Else of ... if ( ( $year === $TodayYear ) && ... */ /* It's NOT today */ 2808 ... { 2809 ... $aCal[$i] = "<td>{$n}</td>"; /* Render the date normally */ 2810 ... } /* End of ... Else of ... if ( ( $year === $TodayYear ) && ... */ 2811 ... } /* End of ... Else of ... if ( $n > $NumberOfDays ) */ 2812 ... 2813 ... if ( $theCallback != null ) /* If callback provided */ 2814 ... { 2815 ... $szCell = $theCallback( "CALENDAR" , /* Type of operation */ 2816 ... $keyword , /* Keyword as it was passed to us */ 2817 ... $lang , /* The language we are operating in */ 2818 ... $aCal[$i] , /* The value of the cell as we have created it */ 2819 ... $year,$month,$day , /* Year, month and day as passed in the URL */ 2820 ... $NumberOfDays , /* Number of days in this month */ 2821 ... $TodayYear,$TodayMonth,$TodayDay, /* Today (year, month, day) */ 2822 ... $i,$n , /* Cell position,day rendered in the cell */ 2823 ... $nPreviousMonth,$nPreviousYear , /* Previous month, previous year */ 2824 ... $nNextMonth,$nNextYear ); /* Next month, next year */ 2825 ... if ( $szCell ) 2826 ... $aCal[$i] = $szCell; 2827 ... } /* if ( $theCallback != null ) */ 2828 ... 2829 ... $n++; /* Next date */ 2830 ... } /* for ( $i = $DayOfTheWeekBOM;( $i<=count($aCal) );$i++ ) */ 2831 ... 2832 ... if ( $bBeforeLastRowVisible ) 2833 ... $szBeforeLastRow = "<tr class=\"day\"> $aCal[29] $aCal[30] $aCal[31] $aCal[32] $aCal[33] $aCal[34] $aCal[35] </tr>"; 2834 ... else 2835 ... $szBeforeLastRow = ''; 2836 ... 2837 ... if ( $bLastRowVisible ) 2838 ... $szLastRow = "<tr class=\"day\"> $aCal[36] $aCal[37] $aCal[38] $aCal[39] $aCal[40] $aCal[41] $aCal[42] </tr>"; 2839 ... else 2840 ... $szLastRow = ''; 2841 ... 2842 ... $szTable = <<< TABLEAU 2843 ... <table class="$cal_class"> 2844 ... 2845 ... <caption title="$szMonth">$szMinus $szMonth $szPlus</caption> 2846 ... 2847 ... <thead> 2848 ... <tr> 2849 ... <th title="$szMonday" >$szMo</th> 2850 ... <th title="$szTuesday" >$szTu</th> 2851 ... <th title="$szWednesday">$szWe</th> 2852 ... <th title="$szThursday" >$szTh</th> 2853 ... <th title="$szFriday" >$szFr</th> 2854 ... <th title="$szSaturday" >$szSa</th> 2855 ... <th title="$szSunday" >$szSu</th> 2856 ... </tr> 2857 ... </thead> 2858 ... <tbody> 2859 ... <tr class="day"> $aCal[1] $aCal[2] $aCal[3] $aCal[4] $aCal[5] $aCal[6] $aCal[7] </tr> 2860 ... <tr class="day"> $aCal[8] $aCal[9] $aCal[10] $aCal[11] $aCal[12] $aCal[13] $aCal[14] </tr> 2861 ... <tr class="day"> $aCal[15] $aCal[16] $aCal[17] $aCal[18] $aCal[19] $aCal[20] $aCal[21] </tr> 2862 ... <tr class="day"> $aCal[22] $aCal[23] $aCal[24] $aCal[25] $aCal[26] $aCal[27] $aCal[28] </tr> 2863 ... {$szBeforeLastRow} 2864 ... {$szLastRow} 2865 ... </tbody> 2866 ... </table> <!-- End of table.{$cal_class} --> 2867 ... TABLEAU; 2868 ... 2869 ... return ( $szTable ); 2870 ... } /* End of function DAT_Calendar() */ 2871 ... /* ================================================================== */ 2872 ... 2873 ... /* ================================================================== */ 2874 ... /* .......................................................................... 2875 ... Function : DrawCalendar() 2876 ... Purpose : Draws a calendar in a table 2877 ... Parameters : year ... the year the calendar should show 2878 ... month ... the month the calendar should show 2879 ... summary ... the summary that is attached to the <table> 2880 ... tag (WACG compliance) 2881 ... lang ... the language of the calendar (fr,en,nl) 2882 ... keyword ... a keyword attached to the calendar. Later on 2883 ... this keyword is passed to your callback 2884 ... function (if any) 2885 ... cal_class 2886 ... callback ... the name of a callback function that is called 2887 ... for every date pertaining to the current month 2888 ... the function is drwaing 2889 ... date_min ... the lower range of the calendar : we won't 2890 ... provide links for dates that are older than 2891 ... this limit (YYYYMMDD format). 2892 ... date_max ... the upper range of the calendar : we won't 2893 ... provide links for dates that are more recent 2894 ... than this limit (YYYYMMDD format). 2895 ... Return : Null 2896 ... .......................................................................... */ 2897 ... function DrawCalendar( $year,$month,$summary = "Calendrier", 2898 ... $lang = "fr",$keyword = '',$cal_class = '', 2899 ... $callback = null,$date_min = null,$date_max = null ) 2900 ... /*-----------------------------------------------------------------------*/ 2901 ... { 2902 ... /******************************************************************/ 2903 ... /* Some words about the callback function: */ 2904 ... /* */ 2905 ... /* A calendar function must be so generic that it can be called */ 2906 ... /* in a lot of different instances: for example to display news, */ 2907 ... /* to display activities, to be used in a blog, etc. */ 2908 ... /* */ 2909 ... /* With that in mind, you quickly realize that the calendar */ 2910 ... /* function cannot be parameterized to a level like the one */ 2911 ... /* needed to face all kind of situations. For example, one may */ 2912 ... /* want the function to render some days of the calendar in bold */ 2913 ... /* in case these dates are holidays, another will want dates in */ 2914 ... /* bold if they are things connected to a date (for example if */ 2915 ... /* news are available at that specific date) ... and even to be */ 2916 ... /* able to link to a given page if that's the case. */ 2917 ... /* */ 2918 ... /* Because of all this, we have decided to let the user do what */ 2919 ... /* he wants by providing a callback mechanism : for each date */ 2920 ... /* of the calendar, we will branch the excution to this callback */ 2921 ... /* function IF provided. This let's people choose what works */ 2922 ... /* better for them. */ 2923 ... /* */ 2924 ... /* This is what the $callback function is all about. We have even */ 2925 ... /* provided the $theCallback variable that will be set to */ 2926 ... /* $callback if the latter is found (function_exists()). */ 2927 ... /* */ 2928 ... /* */ 2929 ... /* */ 2930 ... /* Some other words about the design of the calendar: */ 2931 ... /* */ 2932 ... /* 1) the calendar is rendered as a table */ 2933 ... /* 2) the way the table is presented should be entirely driven */ 2934 ... /* by CSS (no style is given) */ 2935 ... /* */ 2936 ... /******************************************************************/ 2937 ... 2938 ... $theCallback = null; /* Callback function we need to call (none by default) */ 2939 ... 2940 ... if ( $callback != null ) /* If parameter sent */ 2941 ... { 2942 ... $theCallback = function_exists( $callback ) ? $callback : null;/* Set callback to null if function not found */ 2943 ... } /* if ( $callback != null ) */ 2944 ... 2945 ... if ( $lang == null ) /* If language NOT passed */ 2946 ... { 2947 ... $lang = 'fr'; /* Use French by default */ 2948 ... } /* if ( $lang == null ) */ 2949 ... 2950 ... $lang = strtolower( $lang ); /* Turn language to lower case */ 2951 ... 2952 ... if ( $summary == null ) /* If summary NOT provided */ 2953 ... { 2954 ... switch ( $lang ) /* Build summary in function of the language */ 2955 ... { 2956 ... case "en" : $summary = "Calandar (7 columns - 6 rows : 1 column per day)"; break; 2957 ... case "nl" : $summary = "Kalender (7 columns - 6 rows : 1 column per day)"; break; 2958 ... default : $summary = "Calendrier (7 colonnes - 6 lignes : 1 colonne par jour)";break; 2959 ... } /* switch ( $lang ) */ 2960 ... } /* if ( $summary == null ) */ 2961 ... 2962 ... if ( $cal_class == null ) /* If the calendar has NOT been passed a class */ 2963 ... { 2964 ... $cal_class = "calendar"; /* This is the default class assigned to the table */ 2965 ... } /* if ( $cal_class == null ) */ 2966 ... 2967 ... switch ( $lang ) /* Build month and day arrays in function of the language */ 2968 ... { 2969 ... /* -- English --------------------------------------------------------------------------------------------------------- */ 2970 ... case "en" : $aMonths = array( array( "January" ,"February" ,"March" ,"April" ,"May" ,"June" , 2971 ... "July" ,"August" ,"September","October" ,"November" ,"December"), 2972 ... array( "Jan" ,"Feb" ,"Mar" ,"Apr" ,"May" ,"Jun" , 2973 ... "Jul" ,"Aug" ,"Sep" ,"Oct" ,"Nov" ,"Dec" ) ); 2974 ... $aDays = array( array( "Monday" ,"Tuesday" ,"Wednesday","Thursday" ,"Friday" ,"Saturday" ,"Sunday"), 2975 ... array( "Mo" ,"Tu" ,"We" ,"Th" ,"Fr" ,"Sa" ,"Su" ) ); 2976 ... break; 2977 ... /* -- Dutch ----------------------------------------------------------------------------------------------------------- */ 2978 ... case "nl" : $aMonths = array( array( "Januari" ,"Februari" ,"Maart" ,"April" ,"Mei" ,"Juni" , 2979 ... "Juli" ,"Augustus" ,"September","Oktober" ,"November" ,"December"), 2980 ... array( "Janu" ,"Feb" ,"Maa" ,"Apr" ,"Mei" ,"Jun" , 2981 ... "Jul" ,"Aug" ,"Sep" ,"Okt" ,"Nov" ,"Dec" ) ); 2982 ... $aDays = array( array( "Maandag" ,"Dinsdag" ,"Woensdag" ,"Donderdag","Vrijdag" ,"Zaterdag","Zondag"), 2983 ... array( "Ma" ,"Di" ,"Wo" ,"Do" ,"Vr" ,"Za" ,"Zo" ) ); 2984 ... break; 2985 ... /* -- French ---------------------------------------------------------------------------------------------------------- */ 2986 ... default : $aMonths = array( array( "Janvier" ,"Février" ,"Mars" ,"Avril" ,"Mai" ,"Juin" , 2987 ... "Juillet" ,"Août" ,"Septembre","Octobre" ,"Novembre" ,"Décembre"), 2988 ... array( "Jan" ,"Fév" ,"Mar" ,"Avr" ,"Mai" ,"Jun" , 2989 ... "Jul" ,"Aoû" ,"Sep" ,"Oct" ,"Nov" ,"Déc" ) ); 2990 ... $aDays = array( array( "Lundi" ,"Mardi" ,"Mercredi" ,"Jeudi" ,"Vendredi" ,"Samedi","Dimanche"), 2991 ... array( "Lu" ,"Ma" ,"Me" ,"Je" ,"Ve" ,"Sa" ,"Di" ) ); 2992 ... break; 2993 ... } /* switch ( $lang ) */ 2994 ... 2995 ... $szMo = $aDays[1][0]; $szMonday = $aDays[0][0]; /* Monday */ 2996 ... $szTu = $aDays[1][1]; $szTuesday = $aDays[0][1]; /* Tuesday */ 2997 ... $szWe = $aDays[1][2]; $szWednesday = $aDays[0][2]; /* Wednesday */ 2998 ... $szTh = $aDays[1][3]; $szThursday = $aDays[0][3]; /* Thursday */ 2999 ... $szFr = $aDays[1][4]; $szFriday = $aDays[0][4]; /* Friday */ 3000 ... $szSa = $aDays[1][5]; $szSaturday = $aDays[0][5]; /* Saturday */ 3001 ... $szSu = $aDays[1][6]; $szSunday = $aDays[0][6]; /* Sunday */ 3002 ... 3003 ... /* This is an array with all possible dates in the calendar: 3004 ... 3005 ... +---------+--------------+---------+ 3006 ... | < | September 05 | > | 3007 ... +----+----+----+----+----+----+----+ 3008 ... | Mo | Tu | We | Th | Fr | Sa | Su | 3009 ... +----+----+----+----+----+----+----+ 3010 ... | | | | | | | | Row 1 3011 ... +----+----+----+----+----+----+----+ 3012 ... | | | | | | | | Row 2 3013 ... +----+----+----+----+----+----+----+ 3014 ... | | | | | | | | Row 3 3015 ... +----+----+----+----+----+----+----+ 3016 ... | | | | | | | | Row 4 3017 ... +----+----+----+----+----+----+----+ 3018 ... | | | | | | | | Row 5 3019 ... +----+----+----+----+----+----+----+ 3020 ... | | | | | | | | Row 6 3021 ... +----+----+----+----+----+----+----+ 3022 ... 3023 ... Given 6 rows, there are 42 cells in the calendar and this 3024 ... is precisely what the array that follows is all about: 3025 ... */ 3026 ... 3027 ... $e_cell = "<td class=\"empty\"> </td>"; /* This is how an empty cell is represented in the table */ 3028 ... 3029 ... $aCal = array( 1 => $e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell, 3030 ... $e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell, 3031 ... $e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell, 3032 ... $e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell, 3033 ... $e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell, 3034 ... $e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell,$e_cell ); 3035 ... 3036 ... /* Here, we need to know few things about the calendar we're about to display: 3037 ... 3038 ... If we imagine that we're the 4th of September 2005, then we need to know : 3039 ... 3040 ... 1) How many days we have in September 2005 : 30 ($NumberOfDays) 3041 ... 2) What day of the week was the 1st of September 2005 : 3042 ... 4 ... Thursday (0 ... for Sunday, 6 ... for Saturday) 3043 ... ($DayOfTheWeekBOM) 3044 ... 3) What date are we TODAY (day of the month) ($TodayDay) 3045 ... */ 3046 ... 3047 ... $NumberOfDays = date( "t",mktime( 0,0,0,$month,1,$year ) ); /* Number of days in this month */ 3048 ... $DayOfTheWeekBOM = date( "w",mktime( 0,0,0,$month,1,$year ) ); /* What day the 1st of the month was */ 3049 ... $TodayYear = (int) date( "Y" ); /* What year are we today */ 3050 ... $TodayMonth = (int) date( "m" ); /* What month are we today */ 3051 ... $TodayDay = (int) date( "d" ); /* What day are we today */ 3052 ... 3053 ... 3054 ... $DayOfTheWeekBOM = $DayOfTheWeekBOM == 0 ? 7 : $DayOfTheWeekBOM; /* If Sunday ... turn this to 7 instead of 0 */ 3055 ... 3056 ... $szMonth = $aMonths[0][$month-1] . " $year"; /* Form a string similar to "Septembre 2005" */ 3057 ... 3058 ... /* ****************************************************** 3059 ... We need to create 2 links : one to the previous month 3060 ... one to the next month 3061 ... That's what we will be constructing now BUT in case 3062 ... a callback function is provided, then our construction 3063 ... may be invalidated by the callback 3064 ... ***************************************************** */ 3065 ... $nMonth = $month; /* Initialize this variable nMonth */ 3066 ... $nYear = $year; /* Initialize this variable nYear */ 3067 ... 3068 ... DAT_NextMonth( $month,$year,-1,$nMonth,$nYear ); /* Previous month (even if function called NextMonth() */ 3069 ... 3070 ... $nPreviousMonth = $nMonth; /* Remember the value of the previous month (for callback function) */ 3071 ... $nPreviousYear = $nYear; /* Remember the value of the previous year (for callback function) */ 3072 ... 3073 ... $szMinus = ''; /* No link to a previous date by default */ 3074 ... 3075 ... if ( ! is_null( $date_min ) ) /* If a lower range has been set */ 3076 ... { 3077 ... $year_min = (int) substr( $date_min,0,4 ); /* Extract year of lower range */ 3078 ... $month_min = (int) substr( $date_min,4,2 ); /* Extract month of lower range */ 3079 ... 3080 ... if ( $year_min < $nPreviousYear ) /* If previous year still in acceptable range */ 3081 ... { 3082 ... $szMinus = "<a href=\"$nYear/$nMonth/$TodayDay\" title=\"Previous month\"><</a>"; 3083 ... } /* if ( $year_min < $nPreviousYear ) */ 3084 ... elseif ( $year_min == $nPreviousYear ) 3085 ... { 3086 ... if ( $month_min <= $nPreviousMonth ) 3087 ... { 3088 ... $szMinus = "<a href=\"$nYear/$nMonth/$TodayDay\" title=\"Previous month\"><</a>"; 3089 ... } 3090 ... } /* End of ... elseif ( $year_min == $nPreviousYear ) */ 3091 ... } 3092 ... else 3093 ... { 3094 ... $szMinus = "<a href=\"$nYear/$nMonth/$TodayDay\" title=\"Previous month\"><</a>"; 3095 ... } 3096 ... 3097 ... DAT_NextMonth( $month,$year,1,$nMonth,$nYear ); /* Next month */ 3098 ... 3099 ... $nNextMonth = $nMonth; /* Remember the value of next month (for callback function) */ 3100 ... $nNextYear = $nYear; /* Remember the value of next year (for callback function) */ 3101 ... 3102 ... $szPlus = ''; /* No link to a future date by default */ 3103 ... 3104 ... if ( ! is_null( $date_max ) ) /* If a lower range has been set */ 3105 ... { 3106 ... $year_max = (int) substr( $date_max,0,4 ); /* Extract year */ 3107 ... $month_max = (int) substr( $date_max,4,2 ); /* Extract month */ 3108 ... 3109 ... if ( $year_max > $nNextYear ) 3110 ... { 3111 ... $szPlus = "<a href=\"$nYear/$nMonth/$TodayDay\" title=\"Next month\">></a>"; 3112 ... } /* if ( $year_max > $nNextYear ) */ 3113 ... elseif ( $year_max == $nNextYear ) 3114 ... { 3115 ... if ( $month_max >= $nNextMonth ) 3116 ... { 3117 ... $szPlus = "<a href=\"$nYear/$nMonth/$TodayDay\" title=\"Next month\">></a>"; 3118 ... } 3119 ... } /* End of ... elseif ( $year_max == $nNextYear ) */ 3120 ... } 3121 ... else 3122 ... { 3123 ... $szPlus = "<a href=\"$nYear/$nMonth/$TodayDay\" title=\"Next month\">></a>"; 3124 ... } 3125 ... 3126 ... /* OF ... we have done our best : we have provided a link for 3127 ... the previous month and a link to the next month. But as we 3128 ... have said, this can be overruled by the callback function 3129 ... the user has provided. Let's play the game ! 3130 ... */ 3131 ... if ( $theCallback != null ) /* If callback provided */ 3132 ... { 3133 ... $szMinus = $theCallback( "PREVIOUS" , /* Type of operation */ 3134 ... $keyword , /* Keyword as it was passed to us */ 3135 ... $lang , /* The language we are operating in */ 3136 ... $szMinus , /* The value of the previous link as we have created */ 3137 ... $year,$month , /* Year and month of the current calendar view */ 3138 ... $NumberOfDays , /* Number of days in this month */ 3139 ... $TodayYear,$TodayMonth,$TodayDay, /* Today (year, month, day) */ 3140 ... 0,0 , /* Cell position,day rendered in the cell (here N/A => 0) */ 3141 ... $nPreviousMonth,$nPreviousYear , /* Previous month, previous year */ 3142 ... $nNextMonth,$nNextYear , /* Next month, next year */ 3143 ... $date_min,$date_max ); /* Date range */ 3144 ... 3145 ... $szPlus = $theCallback( "NEXT" , /* Type of operation */ 3146 ... $keyword , /* Keyword as it was passed to us */ 3147 ... $lang , /* The language we are operating in */ 3148 ... $szPlus , /* The value of the next link as we have created */ 3149 ... $year,$month , /* Year and month of the current calendar view */ 3150 ... $NumberOfDays , /* Number of days in this month */ 3151 ... $TodayYear,$TodayMonth,$TodayDay, /* Today (year, month, day) */ 3152 ... 0,0 , /* Cell position,day rendered in the cell (here N/A => 0) */ 3153 ... $nPreviousMonth,$nPreviousYear , /* Previous month, previous year */ 3154 ... $nNextMonth,$nNextYear , /* Next month, next year */ 3155 ... $date_min,$date_max ); /* Date range */ 3156 ... } /* if ( $theCallback != null ) */ 3157 ... 3158 ... 3159 ... /* Let's now populate the 42 cells (6 rows of 7 days) with the 3160 ... days corresponding to this month */ 3161 ... 3162 ... $n = 1; 3163 ... 3164 ... /* for ( $i = $DayOfTheWeekBOM;( ( $i<=count($aCal) ) && ( $n <= $NumberOfDays ) );$i++ ) */ 3165 ... for ( $i = $DayOfTheWeekBOM;( $i<=count($aCal) );$i++ ) 3166 ... { 3167 ... if ( $n > $NumberOfDays ) /* If this date falls off the calendar */ 3168 ... { 3169 ... $aCal[$i] = "<td class=\"falloff\"> </td>"; /* Render this date as an empty date (provide CSS for it!) */ 3170 ... } /* if ( $n > $NumberOfDays ) */ 3171 ... else /* Else of ... if ( $n > $NumberOfDays ) */ /* This date is within our acceptable range of dates */ 3172 ... { 3173 ... if ( ( $year === $TodayYear ) && /* If this is TODAY (now) */ 3174 ... ( $month === $TodayMonth ) && 3175 ... ( $n === $TodayDay ) ) 3176 ... { 3177 ... $aCal[$i] = "<td class=\"today\">$n</td>"; /* Mark it as today */ 3178 ... } /* if ( ( $year === $TodayYear ) && ... */ 3179 ... else /* Else of ... if ( ( $year === $TodayYear ) && ... */ /* It's NOT today */ 3180 ... { 3181 ... $aCal[$i] = "<td>$n</td>"; /* Render the date normally */ 3182 ... } /* End of ... Else of ... if ( ( $year === $TodayYear ) && ... */ 3183 ... } /* End of ... Else of ... if ( $n > $NumberOfDays ) */ 3184 ... 3185 ... if ( $theCallback != null ) /* If callback provided */ 3186 ... { 3187 ... $aCal[$i] = $theCallback( "CALENDAR" , /* Type of operation */ 3188 ... $keyword , /* Keyword as it was passed to us */ 3189 ... $lang , /* The language we are operating in */ 3190 ... $aCal[$i] , /* The value of the cell as we have created it */ 3191 ... $year,$month , /* Year and month of the current calendar view */ 3192 ... $NumberOfDays , /* Number of days in this month */ 3193 ... $TodayYear,$TodayMonth,$TodayDay, /* Today (year, month, day) */ 3194 ... $i,$n , /* Cell position,day rendered in the cell */ 3195 ... $nPreviousMonth,$nPreviousYear , /* Previous month, previous year */ 3196 ... $nNextMonth,$nNextYear ); /* Next month, next year */ 3197 ... } /* if ( $theCallback != null ) */ 3198 ... 3199 ... $n++; /* Next date */ 3200 ... } /* for ( $i = $DayOfTheWeekBOM;( $i<=count($aCal) );$i++ ) */ 3201 ... 3202 ... $szTable = <<< TABLEAU 3203 ... <table class="{$cal_class}"> 3204 ... 3205 ... <caption title="$szMonth">$szMinus $szMonth $szPlus</caption> 3206 ... 3207 ... <thead> 3208 ... <tr> 3209 ... <th title="$szMonday" >$szMo</th> 3210 ... <th title="$szTuesday" >$szTu</th> 3211 ... <th title="$szWednesday">$szWe</th> 3212 ... <th title="$szThursday" >$szTh</th> 3213 ... <th title="$szFriday" >$szFr</th> 3214 ... <th title="$szSaturday" >$szSa</th> 3215 ... <th title="$szSunday" >$szSu</th> 3216 ... </tr> 3217 ... </thead> 3218 ... <tbody> 3219 ... <tr class="day"> $aCal[1] $aCal[2] $aCal[3] $aCal[4] $aCal[5] $aCal[6] $aCal[7] </tr> 3220 ... <tr class="day"> $aCal[8] $aCal[9] $aCal[10] $aCal[11] $aCal[12] $aCal[13] $aCal[14] </tr> 3221 ... <tr class="day"> $aCal[15] $aCal[16] $aCal[17] $aCal[18] $aCal[19] $aCal[20] $aCal[21] </tr> 3222 ... <tr class="day"> $aCal[22] $aCal[23] $aCal[24] $aCal[25] $aCal[26] $aCal[27] $aCal[28] </tr> 3223 ... <tr class="day"> $aCal[29] $aCal[30] $aCal[31] $aCal[32] $aCal[33] $aCal[34] $aCal[35] </tr> 3224 ... <tr class="day"> $aCal[36] $aCal[37] $aCal[38] $aCal[39] $aCal[40] $aCal[41] $aCal[42] </tr> 3225 ... </tbody> 3226 ... </table> 3227 ... TABLEAU; 3228 ... 3229 ... return ( $szTable ); 3230 ... } /* End of function DrawCalendar() ======================================= */ 3231 ... 3232 ... /* ========================================================================== */ 3233 ... function Iso8601( $x,$bWithTime = false ) 3234 ... /*-------------------------------------*/ 3235 ... { 3236 ... if ( $bWithTime ) 3237 ... { 3238 ... return ( date( "Y-m-d - H:i:s",$x ) ); 3239 ... } 3240 ... else 3241 ... { 3242 ... return ( date( "Y-m-d",$x ) ); 3243 ... } 3244 ... } /* End of function Iso8601() ============================================ */ 3245 ... 3246 ... /* ========================================================================== */ 3247 ... /** {{*DAT_Full( [$iTime] )= 3248 ... 3249 ... Transforms a time value ([c]time()[/c]) into a string equivalent 3250 ... (DD/MM/YYYY - HH:mm:SS) 3251 ... 3252 ... {*params 3253 ... $iTime (int) Optional time (same format as [c]time()[/c]). 3254 ... If not passed, the current time is considered 3255 ... *} 3256 ... 3257 ... {*return 3258 ... (string) Date and time string DD/MM/YYYY - HH:mm:SS 3259 ... *} 3260 ... 3261 ... {*lupdate 01/06/2014 10:17 *} 3262 ... {*version 5.0.0011 *} 3263 ... 3264 ... {*exec 3265 ... echo '<p>',$szDate1 = DAT_Full( time() - 86400 ),'</p>'; 3266 ... echo '<p>',$szDate2 = DAT_Full() ,'</p>'; 3267 ... 3268 ... echo LSUnitTesting::assert( preg_match( '/\d{2}\/\d{2}\/\d{4} - \d{2}:\d{2}:\d{2}/',$szDate1 ) , 3269 ... "ASSERTION SUCCESSFUL: '{$szDate1}' seems to be a valid date" , 3270 ... "ASSERTION FAILURE: '{$szDate1}' seems to be invalid" , 3271 ... 'GuideAssert' ); 3272 ... echo LSUnitTesting::assert( preg_match( '/\d{2}\/\d{2}\/\d{4} - \d{2}:\d{2}:\d{2}/',$szDate2 ) , 3273 ... "ASSERTION SUCCESSFUL: '{$szDate2}' seems to be a valid date" , 3274 ... "ASSERTION FAILURE: '{$szDate2}' seems to be invalid" , 3275 ... 'GuideAssert' ); 3276 ... *} 3277 ... 3278 ... {*alias 3279 ... FullDateTime(), DATTIME_Full() 3280 ... *} 3281 ... 3282 ... *}} 3283 ... */ 3284 ... /* ====================================================================== */ 3285 ... function DAT_Full( $x = null ) 3286 ... { 3287 ... return ( date( "d/m/Y - H:i:s",is_null( $x ) ? time() : $x ) ); 3288 ... } /* End of function DAT_Full() ======================================= */ 3289 ... function FullDateTime( $x = null ) { return ( DAT_Full( $x ) ); } 3290 ... function DATTIME_Full( $x = null ) { return ( DAT_Full( $x ) ); } 3291 ... 3292 ... /* ====================================================================== */ 3293 ... /** {{*DAT_IsLeap( $iYear )= 3294 ... 3295 ... Determines whether a year is a leap year 3296 ... 3297 ... {*params 3298 ... $iYear (int) Year to analyze 3299 ... *} 3300 ... 3301 ... {*alias 3302 ... IsLeap() 3303 ... *} 3304 ... 3305 ... {*return 3306 ... (bool) true if $iYear is a leap year; false if not 3307 ... *} 3308 ... 3309 ... {*exec 3310 ... for ( $i = 2000; $i <= date( 'Y' );$i++ ) 3311 ... { 3312 ... echo "<p>{$i} <code>IsLeap() (leap year)</code> ? ... " . MISC_CastString( DAT_IsLeap( $i ) ) . '</p>'; 3313 ... } 3314 ... *} 3315 ... 3316 ... {*assert 3317 ... DAT_IsLeap( 1990 ) === false 3318 ... *} 3319 ... {*assert 3320 ... DAT_IsLeap( 1991 ) === false 3321 ... *} 3322 ... {*assert 3323 ... DAT_IsLeap( 1992 ) === true 3324 ... *} 3325 ... {*assert 3326 ... DAT_IsLeap( 2000 ) === true 3327 ... *} 3328 ... 3329 ... *}} 3330 ... */ 3331 ... /* ========================================================================== */ 3332 ... function DAT_IsLeap( $iYear ) 3333 ... /*-------------------------*/ 3334 ... { 3335 ... return ( (! ( $iYear % 4 ) && ( ( $iYear % 100 ) || ! ( $iYear % 400 ) ) ) ); 3336 ... } /* End of function DAT_IsLeap() */ 3337 ... function IsLeap( $iYear ) { return ( DAT_IsLeap( $iYear ) ); } 3338 ... /* ====================================================================== */ 3339 ... 3340 ... function DAT_minus( $szDate1,$szDate2 ) 3341 ... /*-----------------------------------*/ 3342 ... { 3343 ... $nDate1 = mktime( 0,0,0 , 3344 ... (int) substr( $szDate1,4,2 ), 3345 ... (int) substr( $szDate1,6,2 ), 3346 ... (int) substr( $szDate1,0,4 ) ); 3347 ... 3348 ... $nDate2 = mktime( 0,0,0 , 3349 ... (int) substr( $szDate2,4,2 ), 3350 ... (int) substr( $szDate2,6,2 ), 3351 ... (int) substr( $szDate2,0,4 ) ); 3352 ... 3353 ... return ( abs( $nDate2 - $nDate1 ) / 86400 ); 3354 ... } /* End of function DAT_minus() ========================================== */ 3355 ... 3356 ... /* ========================================================================== */ 3357 ... /** {{*TIM_Time2Int( $szHour )= 3358 ... 3359 ... Turns a time representation (string) into an integer 3360 ... 3361 ... {*params 3362 ... $szHour (string) Time string (e.g. "09:14:25" or "09:14" or "09" 3363 ... or "9") 3364 ... *} 3365 ... 3366 ... {*return 3367 ... (int) $szHour turned to an integer 3368 ... *} 3369 ... 3370 ... {*assert 3371 ... TIM_Time2Int('15') === 15 * 3600 3372 ... *} 3373 ... 3374 ... {*assert 3375 ... TIM_Time2Int('00:13') === 13 * 60 3376 ... *} 3377 ... 3378 ... {*assert 3379 ... TIM_Time2Int('15:17') === 15 * 3600 + 17 * 60 3380 ... *} 3381 ... 3382 ... {*assert 3383 ... TIM_Time2Int('15:17:43') === 15 * 3600 + 17 * 60 + 43 3384 ... *} 3385 ... 3386 ... {*exec 3387 ... echo '<p>00:00 = ',TIM_Time2Int('00:00'),'</p>'; 3388 ... echo '<p>01:20 = ',TIM_Time2Int('01:20'),'</p>'; 3389 ... echo '<p>15:17 = ',TIM_Time2Int('15:17'),'</p>'; 3390 ... *} 3391 ... 3392 ... *}} 3393 ... */ 3394 ... /* ========================================================================== */ 3395 ... function TIM_Time2Int( $szHour ) 3396 ... /*----------------------------*/ 3397 ... { 3398 ... $aTokens = explode( ':',$szHour ); 3399 ... $iTokens = min( count( $aTokens ),3 ); 3400 ... 3401 ... for ( $i=0,$iRetVal = 0;$i<$iTokens;$i++ ) 3402 ... $iRetVal += ( (int) $aTokens[$i] ) * pow( 60,(2-$i) ); 3403 ... 3404 ... return ( $iRetVal ); 3405 ... } /* End of function TIM_Time2Int() ======================================= */ 3406 ... 3407 ... /* ========================================================================== */ 3408 ... /** {{*TIM_Int2Time( $iSecs )= 3409 ... 3410 ... Turns a unumber of seconds (integer) to a string representation 3411 ... 3412 ... {*params 3413 ... $iSecs (int) The number of seconds to turn to a time string 3414 ... *} 3415 ... 3416 ... {*return 3417 ... (string) Time string 3418 ... *} 3419 ... 3420 ... {*assert 3421 ... TIM_Int2Time( 2701 ) === '00:45:01' 3422 ... *} 3423 ... 3424 ... {*exec 3425 ... echo '<p>2700 sec (45 min) = ' ,TIM_Int2Time(2700),'</p>'; 3426 ... echo '<p>-2700 sec (45 min) = ' ,TIM_Int2Time(-2700),'</p>'; 3427 ... echo '<p>3600 sec (1 hour) = ' ,TIM_Int2Time(3600),'</p>'; 3428 ... echo '<p>2700000 sec (750 hours) = ',TIM_Int2Time(2700000),'</p>'; 3429 ... *} 3430 ... 3431 ... *}} 3432 ... */ 3433 ... /* ========================================================================== */ 3434 ... function TIM_Int2Time( $iSecs ) 3435 ... /*---------------------------*/ 3436 ... { 3437 ... $iSecs = abs( $iSecs ); 3438 ... $iMinutes = (int) ( $iSecs / 60 ); 3439 ... $iHours = (int) ( $iMinutes / 60 ); 3440 ... $iMinutes = $iMinutes - ( $iHours * 60 ); 3441 ... $iSeconds = $iSecs % 60; 3442 ... return ( STR_padl( (string) $iHours ,2,'0' ) . ':' . 3443 ... STR_padl( (string) $iMinutes,2,'0' ) . ':' . 3444 ... STR_padl( (string) $iSeconds,2,'0' ) ); 3445 ... } /* End of function TIM_Int2Time() ======================================= */ 3446 ... 3447 ... /* ========================================================================== */ 3448 ... /** {{*TIM_Bod( $iTime )= 3449 ... 3450 ... Returns a Unix Timestamp for the start of the day 3451 ... 3452 ... {*params 3453 ... $iTime (int) Optional time to consider. Default is [c]time()[/c]. 3454 ... *} 3455 ... 3456 ... {*return 3457 ... (int) Start of the day timestamp (identical to [c]time()[/c]) 3458 ... *} 3459 ... 3460 ... {*assert 3461 ... TIM_Bod( 1390303904 ) === 1390262400 3462 ... *} 3463 ... 3464 ... {*exec 3465 ... echo '<p>',date( "d/m/Y H:i:s" ),'</p>'; 3466 ... echo '<p>',date( "d/m/Y H:i:s",TIM_Bod() ),'</p>'; 3467 ... echo '<p>',date( "d/m/Y H:i:s",TIM_Bod( time() - ( 4 * 86400 ) ) ),'</p>'; 3468 ... *} 3469 ... 3470 ... *}} 3471 ... */ 3472 ... /* ========================================================================== */ 3473 ... function TIM_Bod( $iTime = null ) 3474 ... /*-----------------------------*/ 3475 ... { 3476 ... if ( is_null( $iTime ) || ! is_integer( $iTime ) ) 3477 ... { 3478 ... $iTime = time(); 3479 ... } 3480 ... 3481 ... $iHours = date( 'H',$iTime ); 3482 ... $iMinutes = date( 'i',$iTime ); 3483 ... $iSeconds = date( 's',$iTime ); 3484 ... 3485 ... $iSecs = ( (int) $iHours * 60 * 60 ) + 3486 ... ( (int) $iMinutes * 60 ) + 3487 ... ( (int) $iSeconds ); 3488 ... 3489 ... return ( $iTime - $iSecs ); 3490 ... } /* End of function TIM_Bod() ============================================ */ 3491 ... 3492 ... /* ========================================================================== */ 3493 ... /** {{*TIM_Add( $szHour,$iSeconds[,$szFormat] )= 3494 ... 3495 ... Adds a number of seconds to a time string 3496 ... 3497 ... {*params 3498 ... $szHour (string) Hours (HH:MM[:SS] format) 3499 ... $iSeconds (int) Number of seconds to add 3500 ... $szFormat (string) Output format. Optional. 'H:i:s' by default 3501 ... (see doc of PHP [c]date()[/c] function) 3502 ... *} 3503 ... 3504 ... {*return 3505 ... (string) Time string 3506 ... *} 3507 ... 3508 ... {*seealso 3509 ... TIM_aSlots() 3510 ... *} 3511 ... 3512 ... {*exec 3513 ... // From 08:00 to 09:00 (step 15 minutes) --------------- 3514 ... $szTime = '08:00:00'; 3515 ... $iSeconds = 900; // 15 minutes 3516 ... for ( $i = 0;$i < 4;$i++ ) 3517 ... { 3518 ... echo "<p>" . TIM_Add( $szTime,$iSeconds,'H:i' ) . "</p>"; 3519 ... $iSeconds += 900; 3520 ... } 3521 ... 3522 ... echo "<hr style=\"border:none;border-top:1px solid silver;\" />"; 3523 ... 3524 ... // From 08:00 to 07:00 (step -10 minutes) -------------- 3525 ... $szTime = '08:00:00'; 3526 ... $iSeconds = 600; // 10 minutes 3527 ... for ( $i = 0;$i <= 6;$i++ ) 3528 ... { 3529 ... echo "<p>" . TIM_Add( $szTime,-($i * $iSeconds),'H:i' ) . "</p>"; 3530 ... } 3531 ... *} 3532 ... *}} 3533 ... */ 3534 ... /* ========================================================================== */ 3535 ... function TIM_Add( $szHour,$iSeconds,$szFormat = 'H:i:s' ) 3536 ... /*-----------------------------------------------------*/ 3537 ... { 3538 ... $aTokens = explode( ':',$szHour ); /* Explode time string */ 3539 ... $iTokens = min( count( $aTokens ),3 ); /* In function of the number of tokens we have */ 3540 ... 3541 ... switch( $iTokens ) 3542 ... { 3543 ... case 1 : $iTime = mktime( (int) $aTokens[0] ) + $iSeconds; 3544 ... break; 3545 ... case 2 : $iTime = mktime( (int) $aTokens[0],(int) $aTokens[1] ) + $iSeconds; 3546 ... break; 3547 ... case 3 : $iTime = mktime( (int) $aTokens[0],(int) $aTokens[1],(int) $aTokens[2] ) + $iSeconds; 3548 ... break; 3549 ... } 3550 ... 3551 ... return ( date( $szFormat,$iTime ) ); /* Return result to caller */ 3552 ... } /* End of function TIM_Add() ============================================ */ 3553 ... 3554 ... /* ========================================================================== */ 3555 ... /** {{*TIM_aSlots( $szStart,$szEnd,$iInterval[,$szFormat] )= 3556 ... 3557 ... Returns an array of time slots between $szStart and $szEnd ($iInterval seconds for each slot) 3558 ... 3559 ... {*params 3560 ... $szStart (string) Hours (HH:MM[:SS] format) 3561 ... $szEnd (string) Hours (HH:MM[:SS] format) 3562 ... $iInterval (int) Number of seconds for each time slot 3563 ... $szFormat (string) Output format. Optional. [c]'H:i:s'[/c] by default 3564 ... (see doc of PHP [c]date()[/c] function) 3565 ... *} 3566 ... 3567 ... {*return 3568 ... (array) Array of time slots ($szFormat applied) 3569 ... *} 3570 ... 3571 ... {*seealso 3572 ... TIM_Add() 3573 ... *} 3574 ... 3575 ... {*exec 3576 ... // From 11:00 to 17:00 (step 20 minutes) --------------- 3577 ... $szStart = '11:00:00'; 3578 ... $szEnd = '17:00:00'; 3579 ... $iInterval = 1200; // 20 minutes 3580 ... $szFormat = 'H:i'; 3581 ... 3582 ... $aSlots = TIM_aSlots( $szStart,$szEnd,$iInterval,$szFormat ); 3583 ... 3584 ... var_dump( $aSlots ); 3585 ... 3586 ... echo LSUnitTesting::assert( count( $aSlots ) === 19 && 3587 ... $aSlots[0] === '11:00' && 3588 ... $aSlots[18] === '17:00' && 3589 ... $aSlots[8] === '13:40' , 3590 ... 'ASSERTION SUCCESSFUL: correct number of slots' , 3591 ... 'ASSERTION FAILURE: incorrect number of slots' , 3592 ... 'GuideAssert' ); 3593 ... 3594 ... 3595 ... *} 3596 ... *}} 3597 ... */ 3598 ... /* ========================================================================== */ 3599 ... function TIM_aSlots( $szStart,$szEnd,$iInterval,$szFormat = 'H:i:s' ) 3600 ... /*-----------------------------------------------------------------*/ 3601 ... { 3602 ... $aSlots = array(); 3603 ... 3604 ... $aSlots[] = $szSlot = TIM_Add( $szStart,0,$szFormat ); 3605 ... $iEnd = TIM_Time2Int( $szEnd ); 3606 ... $iValue = 0; 3607 ... 3608 ... while ( $iValue < $iEnd ) 3609 ... { 3610 ... $aSlots[] = $szSlot = TIM_Add( $szSlot,$iInterval,$szFormat ); 3611 ... $iValue = TIM_Time2Int( $szSlot ); 3612 ... } /* while ( $iValue < $iEnd ) */ 3613 ... 3614 ... return ( $aSlots ); 3615 ... } /* End of function TIM_aSlots() ========================================= */ 3616 ... 3617 ... /* ========================================================================== */ 3618 ... /** {{*TIM_Diff( $szDT1,$szDT2 )= 3619 ... 3620 ... Computes the time difference in seconds between $szDT1 and $szDT2 3621 ... 3622 ... {*params 3623 ... $szDT1 (string) Date time expression (YYYYMMDD[HH:mm:SS]) 3624 ... $szDT2 (string) Date time expression (YYYYMMDD[HH:mm:SS]) 3625 ... *} 3626 ... 3627 ... {*cdate 03/08/2012 21:30:51 *} 3628 ... {*version 5.0.0006 *} 3629 ... 3630 ... {*return 3631 ... (int) Time difference between $szDT1 and $szDT2 (expressed in 3632 ... seconds) 3633 ... *} 3634 ... 3635 ... {*assert 3636 ... TIM_Diff("07:30","08:15") === 2700 3637 ... *} 3638 ... 3639 ... {*assert 3640 ... TIM_Diff("08:15","07:30") === -2700 3641 ... *} 3642 ... 3643 ... {*eTTTxec 3644 ... echo "<p>",TIM_Diff("08:15","07:30"),"</p>"; 3645 ... *} 3646 ... 3647 ... *}} 3648 ... */ 3649 ... /* ========================================================================== */ 3650 ... function TIM_Diff( $szDT1,$szDT2 ) 3651 ... /*------------------------------*/ 3652 ... { 3653 ... return ( TIM_MakeInt( $szDT2 ) - TIM_MakeInt( $szDT1 ) ); 3654 ... } /* End of function TIM_Diff() =========================================== */ 3655 ... ?>
LS_DATES_FUNCTIONS_PWH
: Pat Was Here (PWH)
VAESOLI_PATH
: Define the path where Vae Soli! is installed
VAESOLI_PLUGINS
: Define the path where plugins are located
LSStrings.functions.php
: Vae Soli! string functions
LSUnitTesting.class.php
: Vae Soli! Unit Testing
YYYYMMDD[HHmmSS]
) into an associative arraytime()
)$iTime
time()
) into its day equivalentDD/MM/YYYY
date or an int into a YYYYMMDD
date format$iWeek
time()
)$iTime
time()
) into a string equivalent (DD/MM/YYYY - HH:mm:SS)time()
) into its time (hour) equivalent$szDateTime
is in the future (or same) compared to $szNow
$szDateTime
is in the past (or same) compared to $szNow
time()
) into its time (min) equivalenttime()
) into its month equivalenttime()
) into its time (sec) equivalent$iWeek
time()
) into its year equivalent$iTime
$iTime
$iNow
is a value that has expired compared to $iExpired
$szStart
and $szEnd
($iInterval
seconds for each slot)$szDT1
and $szDT2
$iNow
is between $szStart
and $szStop
time()
) from a YYYYMMDDHHmmSS
valueDAT_2Array()
: Turns a date (YYYYMMDD[HHmmSS]
) into an associative arrayCreated: 16/06/2012 14:14:03
Since version 5.0.0003
DAT_2Array( $szDate,$szPart )
Name | Type | Description |
---|---|---|
$szDate |
mixed | A YYYYMMDD[HHmmSS] date string. If an integer is
supplied, then it is considered as a time()
value on which a date('YmdHis') is applied |
$szPart |
string | Optional parameter: the part to be returned: - 'year' : return the year part as a string - 'month' : return the month part as a string - 'day' : return the day part as a string - 'time' : return the time part as a string |
(mixed) string if $szPart
is passed; array if $szPart
is not mentioned
Example #1 echo DAT_2Array( '20120616140959','time' ); // '140959' Example #2 var_dump( DAT_2Array( '20120616140959' ) ); Example #3 var_dump( DAT_2Array( STR_dionly( '2012-06-16 14:09:59' ) ) );
DAT_2Array( '20120616140959','year' ) == '2012'
successful
DAT_2Array( '20120616140959','month' ) == '06'
successful
DAT_2Array( '20120616140959','day' ) == '16'
successful
DAT_2Array( '20120616140959','time' ) == '140959'
successful
DAT_2Array( '201206161410','time' ) == '1410'
successful
5 assertions: 5 successful; 0 failed
DAT_aDaysAndMonths()
: Creates arrays of days and months namesCreated: 23/07/2012 14:18:22
Since version 5.0.0005
Only English, Dutch and French supported
DAT_aDaysAndMonths( $szLang )
Name | Type | Description |
---|---|---|
$szLang |
string | The language to consider. Optional. French by default. |
(void) No return. Arrays passed are updated upon return
$aDays = array(); $aMonths = array(); DAT_aDaysAndMonths( $aDays,$aMonths,'en' ); var_dump( $aDays ); var_dump( $aMonths ); echo LSUnitTesting::assert( strtolower( $aDays[0][0] ) === 'monday' , 'ASSERTION SUCCESSFUL: day correctly determined', 'ASSERTION FAILURE: incorrect day' , 'GuideAssert' ); echo LSUnitTesting::assert( strtolower( $aDays[1][0] ) === 'mo' , 'ASSERTION SUCCESSFUL: day correctly determined', 'ASSERTION FAILURE: incorrect day' , 'GuideAssert' ); echo LSUnitTesting::assert( strtolower( $aMonths[0][0] ) === 'january' , 'ASSERTION SUCCESSFUL: month correctly determined' , 'ASSERTION FAILURE: incorrect month' , 'GuideAssert' ); echo LSUnitTesting::assert( strtolower( $aMonths[1][0] ) === 'jan' , 'ASSERTION SUCCESSFUL: month correctly determined' , 'ASSERTION FAILURE: incorrect month' , 'GuideAssert' ); DAT_aDaysAndMonths( $aDays,$aMonths ); var_dump( $aDays[0] ); var_dump( $aMonths[0] ); echo LSUnitTesting::assert( strtolower( $aDays[0][0] ) === 'lundi' , 'ASSERTION SUCCESSFUL: day correctly determined', 'ASSERTION FAILURE: incorrect day' , 'GuideAssert' ); echo LSUnitTesting::assert( strtolower( $aDays[1][0] ) === 'lu' , 'ASSERTION SUCCESSFUL: day correctly determined', 'ASSERTION FAILURE: incorrect day' , 'GuideAssert' ); echo LSUnitTesting::assert( strtolower( $aMonths[0][0] ) === 'janvier' , 'ASSERTION SUCCESSFUL: month correctly determined' , 'ASSERTION FAILURE: incorrect month' , 'GuideAssert' ); echo LSUnitTesting::assert( strtolower( $aMonths[1][0] ) === 'jan' , 'ASSERTION SUCCESSFUL: month correctly determined' , 'ASSERTION FAILURE: incorrect month' , 'GuideAssert' );
array (size=2) 0 => array (size=7) 0 => string 'Monday' (length=6) 1 => string 'Tuesday' (length=7) 2 => string 'Wednesday' (length=9) 3 => string 'Thursday' (length=8) 4 => string 'Friday' (length=6) 5 => string 'Saturday' (length=8) 6 => string 'Sunday' (length=6) 1 => array (size=7) 0 => string 'Mo' (length=2) 1 => string 'Tu' (length=2) 2 => string 'We' (length=2) 3 => string 'Th' (length=2) 4 => string 'Fr' (length=2) 5 => string 'Sa' (length=2) 6 => string 'Su' (length=2)array (size=2) 0 => array (size=12) 0 => string 'January' (length=7) 1 => string 'February' (length=8) 2 => string 'March' (length=5) 3 => string 'April' (length=5) 4 => string 'May' (length=3) 5 => string 'June' (length=4) 6 => string 'July' (length=4) 7 => string 'August' (length=6) 8 => string 'September' (length=9) 9 => string 'October' (length=7) 10 => string 'November' (length=8) 11 => string 'December' (length=8) 1 => array (size=12) 0 => string 'Jan' (length=3) 1 => string 'Feb' (length=3) 2 => string 'Mar' (length=3) 3 => string 'Apr' (length=3) 4 => string 'May' (length=3) 5 => string 'Jun' (length=3) 6 => string 'Jul' (length=3) 7 => string 'Aug' (length=3) 8 => string 'Sep' (length=3) 9 => string 'Oct' (length=3) 10 => string 'Nov' (length=3) 11 => string 'Dec' (length=3)GuideAssert() ... ASSERTION SUCCESSFUL: day correctly determined
GuideAssert() ... ASSERTION SUCCESSFUL: day correctly determined
GuideAssert() ... ASSERTION SUCCESSFUL: month correctly determined
GuideAssert() ... ASSERTION SUCCESSFUL: month correctly determined
array (size=7) 0 => string 'Lundi' (length=5) 1 => string 'Mardi' (length=5) 2 => string 'Mercredi' (length=8) 3 => string 'Jeudi' (length=5) 4 => string 'Vendredi' (length=8) 5 => string 'Samedi' (length=6) 6 => string 'Dimanche' (length=8)array (size=12) 0 => string 'Janvier' (length=7) 1 => string 'Février' (length=7) 2 => string 'Mars' (length=4) 3 => string 'Avril' (length=5) 4 => string 'Mai' (length=3) 5 => string 'Juin' (length=4) 6 => string 'Juillet' (length=7) 7 => string 'Août' (length=4) 8 => string 'Septembre' (length=9) 9 => string 'Octobre' (length=7) 10 => string 'Novembre' (length=8) 11 => string 'Décembre' (length=8)GuideAssert() ... ASSERTION SUCCESSFUL: day correctly determined
GuideAssert() ... ASSERTION SUCCESSFUL: day correctly determined
GuideAssert() ... ASSERTION SUCCESSFUL: month correctly determined
GuideAssert() ... ASSERTION SUCCESSFUL: month correctly determined
8 assertions: 8 successful; 0 failed
DAT_Add()
: Adds or substracts a number of days to/from a dateDAT_Add( $iYear,$iMonth,$iDay,$iAdd )
Name | Type | Description |
---|---|---|
$iYear |
int | Year |
$iMonth |
int | Month |
$iDay |
int | Day |
$iAdd |
int | Number of days to add (+) or to substract (-) |
DAT_Add()
uses 4 parameters whereas the suggested limit is 3.
(int) mktime()
expression
echo '<p>',DAT_Add( 2012,5,12,4 ),'</p>'; //1337126400 echo '<p>',date( 'Ymd',1337126400 ),'</p>'; //20120516
DAT_Add( 2012,5,12,4 ) == '1337126400'
successful
DAT_Add( 2012,5,12,4 ) === 1337126400
successful
DAT_Add( 2012,5,12,-1 ) === 1336694400
successful
date( "Ymd",DAT_Add( 2012,6,16,1 ) ) == '20120617'
successful
4 assertions: 4 successful; 0 failed
DAT_Bow()
: Determines the beginning of the week (Monday) of a dateCreated: 22/07/2012 19:32:47
Since version 5.0.0005
Modified: 11/10/2014 11:21
DAT_Bow()
works with a specific date, either in a string format
or in an integer format
DAT_Sow()
works with a specific week
DAT_Eow()
works with a specific week
DAT_Bow( $szDate,$szFormat )
Name | Type | Description |
---|---|---|
$szDate |
string | A date string in YYYYMMDD or in a time()
format |
$szFormat |
string | Output format. Optional. null by default in which
case the return value is an integer (time()
format) |
(int) Time expressed in number of seconds since 01/01/1970 if
$szFormat
== null; otherwise a string format (see date()
function in PHP)
echo "<p>" . ( $iTime1 = DAT_Bow( "20120719" ) ) . "</p>"; echo "<p>" . ( $szTime1 = DAT_Bow( "20120719",'Ymd' ) ) . "</p>"; echo "<p>" . ( $iTime2 = DAT_Bow( "20120722" ) ) . "</p>"; echo "<p>" . ( $szTime2 = DAT_Bow( "20120722",'Ymd' ) ) . "</p>"; echo "<p>" . ( $szTime3 = DAT_Bow( TIM_MakeInt( '20141029'),'Ymd' ) ) . "</p>"; echo LSUnitTesting::assert( $iTime1 === 1342396800 , 'ASSERTION SUCCESSFUL: Date of the week correct', 'ASSERTION FAILURE: Date of the week incorrect' , 'GuideAssert' ); echo LSUnitTesting::assert( $iTime2 === 1342396800 , 'ASSERTION SUCCESSFUL: Date of the week correct', 'ASSERTION FAILURE: Date of the week incorrect' , 'GuideAssert' ); echo LSUnitTesting::assert( $szTime1 === '20120716' , 'ASSERTION SUCCESSFUL: Date of the week correct', 'ASSERTION FAILURE: Date of the week incorrect' , 'GuideAssert' ); echo LSUnitTesting::assert( $szTime2 === '20120716' , 'ASSERTION SUCCESSFUL: Date of the week correct', 'ASSERTION FAILURE: Date of the week incorrect' , 'GuideAssert' ); echo LSUnitTesting::assert( $szTime3 === '20141027' , 'ASSERTION SUCCESSFUL: Date of the week correct', 'ASSERTION FAILURE: Date of the week incorrect' , 'GuideAssert' );
1342396800
20120716
1342396800
20120716
20141027
GuideAssert() ... ASSERTION SUCCESSFUL: Date of the week correct
GuideAssert() ... ASSERTION SUCCESSFUL: Date of the week correct
GuideAssert() ... ASSERTION SUCCESSFUL: Date of the week correct
GuideAssert() ... ASSERTION SUCCESSFUL: Date of the week correct
GuideAssert() ... ASSERTION SUCCESSFUL: Date of the week correct
5 assertions: 5 successful; 0 failed
DAT_Sow()
, DAT_Dow()
, DAT_Eow()
DAT_Boy()
: Determines the beginning of the year value as an int (time()
)Created: 02/01/2013 16:02
Since version 5.0.0011
DAT_Boy( $iYear )
Name | Type | Description |
---|---|---|
$iYear |
integer | The year to consider |
(int) Time expressed in number of seconds since 01/01/1970
(use it subsequently with a call to date()
).
echo "<p>",$n1 = DAT_Boy( 2012 ),' = ',( $szDate1 = date( 'YmdHis',$n1 ) ),"</p>"; echo "<p>",$n2 = DAT_Boy( 2013 ),' = ',( $szDate2 = date( 'YmdHis',$n2 ) ),"</p>"; echo LSUnitTesting::assert( $n1 === 1325376000 , 'ASSERTION SUCCESSFUL: date correctly determined' , 'ASSERTION FAILURE: incorrect date' , 'GuideAssert' ); echo LSUnitTesting::assert( $szDate1 === '20120101000000' , 'ASSERTION SUCCESSFUL: date correctly determined' , 'ASSERTION FAILURE: incorrect date' , 'GuideAssert' );
1325376000 = 20120101000000
1356998400 = 20130101000000
GuideAssert() ... ASSERTION SUCCESSFUL: date correctly determined
GuideAssert() ... ASSERTION SUCCESSFUL: date correctly determined
date( 'YmdHis',DAT_Boy( 2013 ) ) === '20130101000000'
successful
3 assertions: 3 successful; 0 failed
DAT_British()
: Returns the british representation of a date based on $iTime
Since version 5.0.0003
DAT_British( $iTime,$szFormat )
Name | Type | Description |
---|---|---|
$iTime |
int | time() representation |
$szFormat |
string | Optional format of the output. 'm/d/Y' by default |
(string) Date representation (Sat 16 June 2012 is represented as '16/06/2012')
echo DAT_British( 1339856589 ); // Prints '16/06/2012' echo DAT_British( 1339856589,'Y' ); // Prints '2012' echo DAT_British( 1339856589,'d/m/Y H i s' ); // Prints '16/06/2012 14 23 09'
DAT_British( 1339856589 ) == '16/06/2012'
successful
1 assertions: 1 successful; 0 failed
DATTIME_French()
, DAT_French()
, DATTIME_British()
DAT_cDow()
: Returns the day of the week from a given date or day in a weekCreated: 23/07/2012 14:32:29
Since version 5.0.0005
DAT_cDow( $xDate,$bLong,$szLang )
Name | Type | Description |
---|---|---|
$xDate |
mixed | Date string in YYYYMMDD format, or UNIX
time equivalent as an int , or day of the
week (int between 1 and 7). |
$bLong |
bool | Long (true) or short (false) format. Optional. Long by default. |
$szLang |
string | Language (en,fr or nl). Optional: 'fr' by default. |
(string) Returns the name of the day of the week as a string in proper noun format.
echo '<ol>'; echo '<li> ... ',( $szDate01 = DAT_cDow( "20120722" ) ),'</li>'; echo '<li> ... ',( $szDate02 = DAT_cDow( TIM_MakeInt( "20120722" ) ) ),'</li>'; echo '<li> ... ',( $szDate03 = DAT_cDow( null ) ),'</li>'; echo '<li> ... ',( $szDate04 = DAT_cDow( 1,true ,'en' ) ),'</li>'; echo '<li> ... ',( $szDate05 = DAT_cDow( 7,true ,'en' ) ),'</li>'; echo '<li> ... ',( $szDate06 = DAT_cDow( 1,true ,'fr' ) ),'</li>'; echo '<li> ... ',( $szDate07 = DAT_cDow( 7,true ,'fr' ) ),'</li>'; echo '<li> ... ',( $szDate08 = DAT_cDow( 1,true ,'nl' ) ),'</li>'; echo '<li> ... ',( $szDate09 = DAT_cDow( 7,true ,'nl' ) ),'</li>'; echo '<li> ... ',( $szDate10 = DAT_cDow( 3,false ,'fr' ) ),'</li>'; echo '</ol>'; echo LSUnitTesting::assert( strtolower( $szDate01 ) === 'dimanche' , 'ASSERTION SUCCESSFUL: day of the week correctly determined', 'ASSERTION FAILURE: incorrect day of the week' , 'GuideAssert' ); echo LSUnitTesting::assert( strtolower( $szDate09 ) === 'zondag' , 'ASSERTION SUCCESSFUL: day of the week correctly determined', 'ASSERTION FAILURE: incorrect day of the week' , 'GuideAssert' ); echo LSUnitTesting::assert( strtolower( $szDate10 ) === 'me' , 'ASSERTION SUCCESSFUL: day of the week correctly determined', 'ASSERTION FAILURE: incorrect day of the week' , 'GuideAssert' );
- ... Dimanche
- ... Dimanche
- ... Mercredi
- ... Monday
- ... Sunday
- ... Lundi
- ... Dimanche
- ... Maandag
- ... Zondag
- ... Me
GuideAssert() ... ASSERTION SUCCESSFUL: day of the week correctly determined
GuideAssert() ... ASSERTION SUCCESSFUL: day of the week correctly determined
GuideAssert() ... ASSERTION SUCCESSFUL: day of the week correctly determined
DAT_cDow( 4,false,'fr' ) === 'Je'
successful
DAT_cDow( 5,false,'nl' ) === 'Vr'
successful
DAT_cDow( 5,true,'nl' ) === 'Vrijdag'
successful
6 assertions: 6 successful; 0 failed
DAT_cMonth()
: Returns the name of the month from a given date or month of yearCreated: 23/07/2012 16:15:17
Since version 5.0.0005
DAT_cMonth( $xDate,$bLong,$szLang )
Name | Type | Description |
---|---|---|
$xDate |
mixed | Date string in YYYYMMDD format, or UNIX time
equivalent as an int , or month of the year
(int between 1 and 12). |
$bLong |
bool | Long (true) or short (false) format. Optional. Long by default. |
$szLang |
string | Language (en,fr or nl). Optional: 'fr' by default. |
(string) Returns the name of the month as a string in proper noun format
- ... Juillet
- ... Juillet
- ...
- ... January
- ... December
- ... Janvier
- ... Décembre
- ... Januari
- ... December
- ... Jun
GuideAssert() ... ASSERTION SUCCESSFUL: month of the year correctly determined
GuideAssert() ... ASSERTION SUCCESSFUL: month of the year correctly determined
GuideAssert() ... ASSERTION SUCCESSFUL: month of the year correctly determined
GuideAssert() ... ASSERTION SUCCESSFUL: month of the year correctly determined
GuideAssert() ... ASSERTION SUCCESSFUL: month of the year correctly determined
5 assertions: 5 successful; 0 failed
DAT_Day()
: Transforms a time value (time()
) into its day equivalentSince version 5.0.0011
DAT_Day( $iTime )
Name | Type | Description |
---|---|---|
$iTime |
int | Optional time (same format as time() ).
If not passed, the current time is considered |
(int) Day value of the time
$iTime = time(); echo "<p>{$iTime} = " . date( "d-m-Y H:i:s",$iTime ) . "</p>"; // 1336805092 = 12-05-2012 06:44:52 echo "<p>Day = " . DAT_Day( $iTime ) . "</p>"; // Day = 12
echo '<p>',$iNow = 1382590417,'</p>'; echo '<p>',$szDate = date( 'YmdHis',$iNow ),'</p>'; echo '<p>',$iDay = DAT_Day( $iNow ),'</p>'; echo LSUnitTesting::assert( $iDay === (int) substr( $szDate,6,2 ) , 'ASSERTION SUCCESSFUL: day correctly determined', 'ASSERTION FAILURE: incorrect day' , 'GuideAssert' );
1382590417
20131024045337
24
GuideAssert() ... ASSERTION SUCCESSFUL: day correctly determined
1 assertions: 1 successful; 0 failed
DAT_Month()
, DAT_Year()
, DAT_Dow()
, DAT_cDow()
DAT_Diff()
: Time difference between 2 dates (only YYYYMMDD taken into consideration)Created: 16/06/2012 14:18:13
Since version 5.0.0003
DAT_Diff( $aDate1,$aDate2 )
Name | Type | Description |
---|---|---|
$aDate1 |
array | An associative array with 'year','month','day' slots |
$aDate2 |
array | An associative array with 'year','month','day' slots |
(int) time difference in seconds (absolute value). -1 is returned in case of problem.
echo '<p>',DAT_Add( 2012,5,12,4 ),'</p>'; //1337126400 echo '<p>',date( 'Ymd',1337126400 ),'</p>'; //20120516
DAT_Diff( DAT_2Array( '20120616' ),DAT_2Array( '20120617' ) ) == 86400
successful
1 assertions: 1 successful; 0 failed
DAT_Dow()
: Determines the week of the day value of a given dateCreated: 22/07/2012 19:32:47
Since version 5.0.0005
This function behaves differently from PHP (Sunday = 7)
DAT_Dow( $xDate )
Name | Type | Description |
---|---|---|
$xDate |
mixed | Date string in YYYYMMDD format or UNIX time
equivalent as an int . Optional. Defaulted to
current time value (time() ). |
(int) Day of the week. 1 for Monday; 7 for Sunday. -1 in case of error.
echo '<p>' . ( $iDay1 = DAT_Dow( $szDate = "20120722" ) ) . '</p>'; echo '<p>' . ( $iDay2 = DAT_Dow( TIM_MakeInt( $szDate ) ) ) . '</p>'; echo '<p>' . ( $iDay3 = DAT_Dow( null ) ) . '</p>'; echo '<p>' . ( $iDay4 = DAT_Dow() ) . '</p>'; echo LSUnitTesting::assert( $iDay1 === 7 , 'ASSERTION SUCCESSFUL: day of the week correct' , 'ASSERTION FAILURE: incorrect day of the week' , 'GuideAssert' ); echo LSUnitTesting::assert( $iDay2 === $iDay1 , 'ASSERTION SUCCESSFUL: day of the week correct' , 'ASSERTION FAILURE: incorrect day of the week' , 'GuideAssert' );
7
7
3
3
GuideAssert() ... ASSERTION SUCCESSFUL: day of the week correct
GuideAssert() ... ASSERTION SUCCESSFUL: day of the week correct
2 assertions: 2 successful; 0 failed
DAT_dtos()
: Turns a DD/MM/YYYY
date or an int into a YYYYMMDD
date formatDAT_dtos( $xDate )
Name | Type | Description |
---|---|---|
$xDate |
unknown | (string|int) Date string (DD/MM/YYYY or
YYYY/MM/DD format). If $xDate is an
integer, then it is treated as if it were a
time() value |
(string) $xDate
turned to a YYYYMMDD
format; null
if
incorrect $xDate
.
echo DAT_dtos( '01/01/2012' ); echo DAT_dtos( '48/7/3013' );
20120101
DAT_dtos( '01/01/2012' ) === '20120101'
successful
DAT_dtos( '31/12/2013' ) === '20131231'
successful
is_null( DAT_dtos( '48/7/2013' ) )
successful
3 assertions: 3 successful; 0 failed
DAT_Eom()
: Returns the day that is the end of the monthCreated: 17/03/2013 18:42
Since version 5.1.0001
DAT_Eom( $iMonth,$iYear )
Name | Type | Description |
---|---|---|
$iMonth |
int | Optional month to consider. Current month by default. |
$iYear |
int | Optional year to consider. Current year by default. |
(int) The day that is the last day of the month
DAT_Eom( 1 ) === 31
successful
DAT_Eom( 2,2012 ) === 29
successful
DAT_Eom( 2,2013 ) === 28
successful
DAT_Eom( 3 ) === 31
successful
DAT_Eom( 4 ) === 30
successful
DAT_Eom( 12 ) === 31
successful
6 assertions: 6 successful; 0 failed
DAT_Eow()
: End of the week of $iWeek
Since version 5.6.0004
Modified: 23/10/2013 20:16
DAT_Bow()
works with a specific date, either in a string format
or in an integer format
DAT_Sow()
works with a specific week
DAT_Eow()
works with a specific week
DAT_Eow( $iWeek,$iYear )
Name | Type | Description |
---|---|---|
$iWeek |
int | Week number |
$iYear |
int | Year to consider. Optional. Default is current year |
(string) End of the week for $iWeek
(YYYYMMDD format)
DAT_Eow( 45,2013 ) === '20131110'
successful
DAT_Eow( 45,2014 ) === '20141109'
successful
2 assertions: 2 successful; 0 failed
DAT_Eoy()
: Determines the end of the year value as an int (time()
)Created: 24/10/2013 09:19
Since version 5.6.0004
DAT_Eoy( $iYear )
Name | Type | Description |
---|---|---|
$iYear |
integer | The year to consider |
(int) Time expressed in number of seconds since 01/01/1970
(use it subsequently with a call to date()
).
echo "<p>",$n1 = DAT_Eoy( 2012 ),' = ',( $szDate1 = date( 'YmdHis',$n1 ) ),"</p>"; echo "<p>",$n2 = DAT_Eoy( 2013 ),' = ',( $szDate2 = date( 'YmdHis',$n2 ) ),"</p>"; echo LSUnitTesting::assert( $szDate1 === '20121231235959' , 'ASSERTION SUCCESSFUL: date correctly determined' , 'ASSERTION FAILURE: incorrect date' , 'GuideAssert' ); echo LSUnitTesting::assert( $szDate2 === '20131231235959' , 'ASSERTION SUCCESSFUL: date correctly determined' , 'ASSERTION FAILURE: incorrect date' , 'GuideAssert' );
1356998399 = 20121231235959
1388534399 = 20131231235959
GuideAssert() ... ASSERTION SUCCESSFUL: date correctly determined
GuideAssert() ... ASSERTION SUCCESSFUL: date correctly determined
2 assertions: 2 successful; 0 failed
DAT_French()
: Returns the french representation of a date based on $iTime
Since version 5.0.0003
DAT_French( $iTime,$szFormat )
Name | Type | Description |
---|---|---|
$iTime |
int | time() representation |
$szFormat |
string | Optional format of the output. 'm-d-Y' by default |
(string) Date representation (Sat 16 June 2012 is represented as '16-06-2012')
echo DAT_French( 1339856589 ); // Prints '16-06-2012' echo DAT_French( 1339856589,'Y' ); // Prints '2012' echo DAT_French( 1339856589,'d-m-Y H:i:s' ); // Prints '16-06-2012 14:23:09'
DAT_French( 1339856589 ) == '16-06-2012'
successful
1 assertions: 1 successful; 0 failed
DATTIME_French()
, DAT_British()
, DATTIME_British()
DAT_Full()
: Transforms a time value (time()
) into a string equivalent (DD/MM/YYYY - HH:mm:SS)Since version 5.0.0011
DAT_Full( $iTime )
FullDateTime(), DATTIME_Full()
Name | Type | Description |
---|---|---|
$iTime |
int | Optional time (same format as time() ).
If not passed, the current time is considered |
(string) Date and time string DD/MM/YYYY - HH:mm:SS
echo '<p>',$szDate1 = DAT_Full( time() - 86400 ),'</p>'; echo '<p>',$szDate2 = DAT_Full() ,'</p>'; echo LSUnitTesting::assert( preg_match( '/\d{2}\/\d{2}\/\d{4} - \d{2}:\d{2}:\d{2}/',$szDate1 ) , "ASSERTION SUCCESSFUL: '{$szDate1}' seems to be a valid date" , "ASSERTION FAILURE: '{$szDate1}' seems to be invalid" , 'GuideAssert' ); echo LSUnitTesting::assert( preg_match( '/\d{2}\/\d{2}\/\d{4} - \d{2}:\d{2}:\d{2}/',$szDate2 ) , "ASSERTION SUCCESSFUL: '{$szDate2}' seems to be a valid date" , "ASSERTION FAILURE: '{$szDate2}' seems to be invalid" , 'GuideAssert' );
31/03/2015 - 16:19:49
01/04/2015 - 16:19:49
GuideAssert() ... ASSERTION SUCCESSFUL: '31/03/2015 - 16:19:49' seems to be a valid date
GuideAssert() ... ASSERTION SUCCESSFUL: '01/04/2015 - 16:19:49' seems to be a valid date
2 assertions: 2 successful; 0 failed
DAT_Hour()
: Transforms a time value (time()
) into its time (hour) equivalentSince version 5.0.0011
DAT_Hour( $iTime )
DAT_Hours(), TIM_Hour(), TIM_Hours()
Name | Type | Description |
---|---|---|
$iTime |
int | Optional time (same format as time() ).
If not passed, the current time is considered |
(int) Hour value of the time
echo '<p>',$iNow = 1382590417,'</p>'; echo '<p>',$szDate = date( 'YmdHis',$iNow ),'</p>'; echo '<p>',$iMonth = DAT_Month( $iNow ),'</p>'; echo '<p>',$iDay = DAT_Day( $iNow ),'</p>'; echo '<p>',$iYear = DAT_Year( $iNow ),'</p>'; echo '<p>',$iHours = DAT_Hour( $iNow ),'</p>'; echo '<p>',$iMins = DAT_Min( $iNow ),'</p>'; echo '<p>',$iSecs = DAT_Sec( $iNow ),'</p>'; echo LSUnitTesting::assert( $iHours === (int) substr( $szDate,8,2 ) , 'ASSERTION SUCCESSFUL: hour correctly determined', 'ASSERTION FAILURE: incorrect hour' , 'GuideAssert' );
1382590417
20131024045337
10
24
2013
4
53
37
GuideAssert() ... ASSERTION SUCCESSFUL: hour correctly determined
1 assertions: 1 successful; 0 failed
DAT_Day()
, DAT_Month()
, DAT_Year()
, DAT_Min()
, DAT_Sec()
DAT_IsFuture()
: Determines whether $szDateTime
is in the future (or same) compared to $szNow
DAT_IsFuture( $szDateTime,$szNow )
Name | Type | Description |
---|---|---|
$szDateTime |
string | Date / Time to test (YYYYMMDD[HHmmSS] format) |
$szNow |
string | Optional value to compare $szDateTime with
(YYYYMMDD[HHmmSS] format). If not set,
date('YmdHis') is assumed. |
(bool) true
if $szDateTime
>= $szNow
; false
otherwise
! DAT_IsFuture( '20131231' ,'20131231235959' )
successful
DAT_IsFuture( '20131231150000' ,'20131231' )
successful
! DAT_IsFuture( '20131231150000' ,'20131231160000' )
successful
DAT_IsFuture( '2013123116' ,'20131231160000' )
successful
! DAT_IsFuture( '19000101' )
successful
5 assertions: 5 successful; 0 failed
DAT_IsPast()
, SetExpiry()
, IsExpired()
DAT_IsLeap()
: Determines whether a year is a leap yearDAT_IsLeap( $iYear )
IsLeap()
Name | Type | Description |
---|---|---|
$iYear |
int | Year to analyze |
(bool) true if $iYear
is a leap year; false if not
for ( $i = 2000; $i <= date( 'Y' );$i++ ) { echo "<p>{$i} <code>IsLeap() (leap year)</code> ? ... " . MISC_CastString( DAT_IsLeap( $i ) ) . '</p>'; }
2000
IsLeap() (leap year)
? ... true2001
IsLeap() (leap year)
? ... false2002
IsLeap() (leap year)
? ... false2003
IsLeap() (leap year)
? ... false2004
IsLeap() (leap year)
? ... true2005
IsLeap() (leap year)
? ... false2006
IsLeap() (leap year)
? ... false2007
IsLeap() (leap year)
? ... false2008
IsLeap() (leap year)
? ... true2009
IsLeap() (leap year)
? ... false2010
IsLeap() (leap year)
? ... false2011
IsLeap() (leap year)
? ... false2012
IsLeap() (leap year)
? ... true2013
IsLeap() (leap year)
? ... false2014
IsLeap() (leap year)
? ... false2015
IsLeap() (leap year)
? ... false
DAT_IsLeap( 1990 ) === false
successful
DAT_IsLeap( 1991 ) === false
successful
DAT_IsLeap( 1992 ) === true
successful
DAT_IsLeap( 2000 ) === true
successful
4 assertions: 4 successful; 0 failed
DAT_IsPast()
: Determines whether $szDateTime
is in the past (or same) compared to $szNow
DAT_IsPast( $szDateTime,$szNow )
Name | Type | Description |
---|---|---|
$szDateTime |
string | Date / Time to test (YYYYMMDD[HHmmSS] format) |
$szNow |
string | Optional value to compare $szDateTime with
(YYYYMMDD[HHmmSS] format). If not set,
date('YmdHis') is assumed. |
(bool) true
if $szDateTime
<= $szNow
; false
otherwise
if ( DAT_IsPast( $dt1 = '20131231',$dt2 = '20131231235959' ) ) echo "<p>{$dt1} <= {$dt2}</p>"; else echo "<p>{$dt1} > {$dt2}</p>"; if ( DAT_IsPast( $dt1 = '20131231150000',$dt2 = '20131231' ) ) echo "<p>{$dt1} <= {$dt2}</p>"; else echo "<p>{$dt1} > {$dt2}</p>"; if ( DAT_IsPast( $dt1 = '20131231150000',$dt2 = '20131231160000' ) ) echo "<p>{$dt1} <= {$dt2}</p>"; else echo "<p>{$dt1} > {$dt2}</p>"; if ( DAT_IsPast( $dt1 = '20131231130000',$dt2 = '20131231160000' ) ) echo "<p>{$dt1} <= {$dt2}</p>"; else echo "<p>{$dt1} > {$dt2}</p>";
20131231 <= 20131231235959
20131231150000 <= 20131231
20131231150000 <= 20131231160000
20131231130000 <= 20131231160000
DAT_IsPast( '20131231','20131231235959' ) == true
successful
DAT_IsPast( '20131231150000', '20131231' ) == true
successful
DAT_IsPast( '20150101', '20140101' ) == false
successful
DAT_IsPast( '20140101', '20150101' ) == true
successful
4 assertions: 4 successful; 0 failed
DAT_IsFuture()
, SetExpiry()
, IsExpired()
DAT_Min()
: Transforms a time value (time()
) into its time (min) equivalentSince version 5.0.0011
DAT_Min( $iTime )
DAT_Mins(), TIM_Min(), TIM_Mins()
Name | Type | Description |
---|---|---|
$iTime |
int | Optional time (same format as time() ).
If not passed, the current time is considered |
(int) Minute value of the time
$iNow = time(); $iMonth = DAT_Month( $iNow ); $iDay = DAT_Day( $iNow ); $iYear = DAT_Year( $iNow ); $iHours = DAT_Hour( $iNow ); $iMins = DAT_Min( $iNow ); $iSecs = DAT_Sec( $iNow );
echo '<p>',$iNow = 1382590417,'</p>'; echo '<p>',$szDate = date( 'YmdHis',$iNow ),'</p>'; echo '<p>',$iMins = DAT_Min( $iNow ),'</p>'; echo LSUnitTesting::assert( $iMins === (int) substr( $szDate,10,2 ) , 'ASSERTION SUCCESSFUL: minutes correctly determined', 'ASSERTION FAILURE: incorrect minutes' , 'GuideAssert' );
1382590417
20131024045337
53
GuideAssert() ... ASSERTION SUCCESSFUL: minutes correctly determined
1 assertions: 1 successful; 0 failed
DAT_Day()
, DAT_Month()
, DAT_Year()
, DAT_Hour()
, DAT_Sec()
DAT_Month()
: Transforms a time value (time()
) into its month equivalentSince version 5.0.0011
DAT_Month( $iTime )
Name | Type | Description |
---|---|---|
$iTime |
int | Optional time (same format as time() ).
If not passed, the current time is considered |
(int) Month value of the time
echo '<p>',$iNow = 1382590417,'</p>'; echo '<p>',$szDate = date( 'YmdHis',$iNow ),'</p>'; echo '<p>',$iMonth = DAT_Month( $iNow ),'</p>'; echo '<p>',$iDay = DAT_Day( $iNow ),'</p>'; echo '<p>',$iYear = DAT_Year( $iNow ),'</p>'; echo '<p>',$iHours = DAT_Hour( $iNow ),'</p>'; echo '<p>',$iMins = DAT_Min( $iNow ),'</p>'; echo '<p>',$iSecs = DAT_Sec( $iNow ),'</p>'; echo LSUnitTesting::assert( $iMonth === (int) substr( $szDate,4,2 ) , 'ASSERTION SUCCESSFUL: month correctly determined' , 'ASSERTION FAILURE: incorrect month' , 'GuideAssert' );
1382590417
20131024045337
10
24
2013
4
53
37
GuideAssert() ... ASSERTION SUCCESSFUL: month correctly determined
1 assertions: 1 successful; 0 failed
DAT_Day()
, DAT_Year()
, DAT_cMonth()
DAT_NextMonth()
: Determines the next month of a date (n added or substracted)DAT_NextMonth( $month,$year,$n,$nMonth,$nYear )
Name | Type | Description |
---|---|---|
$month |
int | Starting month |
$year |
int | Starting year |
$n |
int | Number of months to jump (can be negative) |
$nMonth |
int | By reference. Resulting month |
$nYear |
int | By reference. Resulting year |
DAT_NextMonth()
uses 5 parameters whereas the suggested limit is 3.
(void)
$iMonth = $iYear = -1; DAT_NextMonth( 12,2012,-13,$iMonth,$iYear ); echo '<p>',$iMonth,'/',$iYear,'</p>'; // 11/2011 echo LSUnitTesting::assert( $iMonth === 11 && $iYear === 2011 , 'ASSERTION SUCCESSFUL: month and year correctly determined' , 'ASSERTION FAILURE: incorrect month and/or year' , 'GuideAssert' ); DAT_NextMonth( 12,2012,1,$iMonth,$iYear ); echo '<p>',$iMonth,'/',$iYear,'</p>'; // 1/2013 echo LSUnitTesting::assert( $iMonth === 1 && $iYear === 2013 , 'ASSERTION SUCCESSFUL: month and year correctly determined' , 'ASSERTION FAILURE: incorrect month and/or year' , 'GuideAssert' );
11/2011
GuideAssert() ... ASSERTION SUCCESSFUL: month and year correctly determined
1/2013
GuideAssert() ... ASSERTION SUCCESSFUL: month and year correctly determined
2 assertions: 2 successful; 0 failed
DAT_Sec()
: Transforms a time value (time()
) into its time (sec) equivalentSince version 5.0.0011
DAT_Sec( $iTime )
DAT_Secs(), TIM_Sec(), TIM_Secs()
Name | Type | Description |
---|---|---|
$iTime |
int | Optional time (same format as time() ).
If not passed, the current time is considered |
(int) Seconds value of the time
$iNow = time(); $iMonth = DAT_Month( $iNow ); $iDay = DAT_Day( $iNow ); $iYear = DAT_Year( $iNow ); $iHours = DAT_Hour( $iNow ); $iMins = DAT_Min( $iNow ); $iSecs = DAT_Sec( $iNow );
echo '<p>',$iNow = 1382590417,'</p>'; echo '<p>',$szDate = date( 'YmdHis',$iNow ),'</p>'; echo '<p>',$iSecs = DAT_Sec( $iNow ),'</p>'; echo LSUnitTesting::assert( $iSecs === (int) substr( $szDate,12,2 ) , 'ASSERTION SUCCESSFUL: secs correctly determined' , 'ASSERTION FAILURE: incorrect secs' , 'GuideAssert' );
1382590417
20131024045337
37
GuideAssert() ... ASSERTION SUCCESSFUL: secs correctly determined
1 assertions: 1 successful; 0 failed
DAT_Day()
, DAT_Month()
, DAT_Year()
, DAT_Hour()
, DAT_Min()
DAT_Sow()
: Start of the week of $iWeek
Since version 5.6.0004
Modified: 23/10/2013 20:16
DAT_Bow()
works with a specific date, either in a string format
or in an integer format
DAT_Sow()
works with a specific week
DAT_Eow()
works with a specific week
DAT_Sow( $iWeek,$iYear )
Name | Type | Description |
---|---|---|
$iWeek |
int | Week number |
$iYear |
int | Year to consider. Optional. Default is current year |
(string) Start of the week for $iWeek
(YYYYMMDD format)
DAT_Sow( 45,2013 ) === '20131104'
successful
1 assertions: 1 successful; 0 failed
DAT_Bow()
, DAT_Week2Date()
, DAT_Eow()
DAT_Split()
: Splits a YYYYMMDD[HHmmSS] date into an associative arraySTR_Empty()
, STR_dionly()
DAT_Split( $szDate )
Name | Type | Description |
---|---|---|
$szDate |
string | A YYYYMMDD[HHmmSS] date string |
(array)
a['year']
= YYYY
a['month']
= MM
a['day']
= DD
a['hour']
= HH
a['min']
= mm
a['sec']
= SS
$aDate = DAT_Split( '20120616140959' ); echo "<p>{$aDate['year']}</p>"; echo "<p>{$aDate['month']}</p>"; echo "<p>{$aDate['day']}</p>"; echo "<p>{$aDate['hour']}</p>"; echo "<p>{$aDate['min']}</p>"; echo "<p>{$aDate['sec']}</p>";
2012
6
16
14
9
59
WARNING: No Unit Testing found. Please provide assertions with assertion constructs ({*assert ... *}
) or with GuideAssert()
function calls in exec constructs ({*exec LSUnitTesting::assert(...); *}
).
DAT_Week2Date()
: Transforms a week number to the Monday date of that weekCreated: 02/01/2013 15:56:31
Since version 5.0.0011
DAT_Week2Date( $iWeek,$iYear )
Name | Type | Description |
---|---|---|
$iWeek |
int | Week number |
$iYear |
int | Year to consider. Optional. Default is current year |
(int) Time value of the date (time()
)
echo '<p>Week 14 of 2013 starts on ' . date('d/m/Y',DAT_Week2Date( 14,2013 ) ) . '</p>'; echo '<p>Week 14 of 2014 starts on ' . date('d/m/Y',DAT_Week2Date( 14,2014 ) ) . '</p>';
Week 14 of 2013 starts on 01/04/2013
Week 14 of 2014 starts on 31/03/2014
date( 'd/m/Y H:i:s',DAT_Week2Date( 14,2013 ) ) === '01/04/2013 00:00:00'
successful
date( 'd/m/Y H:i:s',DAT_Week2Date( 14,2014 ) ) === '31/03/2014 00:00:00'
successful
2 assertions: 2 successful; 0 failed
DAT_WeekNo()
, DAT_Sow()
, DAT_Eow()
DAT_WeekNo()
: Returns the week number of year (ISO-8601 week number of year, weeks starting on Monday )Since version 5.0.0003
DAT_WeekNo( $szDate )
Name | Type | Description |
---|---|---|
$szDate |
string | A date in the YYYYMMDD format |
(int) Week number
echo '<p>Week of the year: ',DAT_WeekNo( '20120616' ),'</p>'; // Week of the year: 24
DAT_WeekNo( '20120616') == 24
successful
1 assertions: 1 successful; 0 failed
DAT_Year()
: Transforms a time value (time()
) into its year equivalentSince version 5.0.0011
Modified: 26/12/2012 17:14:52
DAT_Year( $iTime )
Name | Type | Description |
---|---|---|
$iTime |
int | Optional time (same format as time() ).
If not passed, the current time is considered |
(int) Year value of the time
$iTime = time(); echo "<p>{$iTime} = " . date( "d-m-Y H:i:s",$iTime ) . "</p>"; // 1336805092 = 12-05-2012 06:44:52 echo "<p>Year = " . DAT_Year( $iTime ) . "</p>"; // Year = 2012
echo '<p>',$iNow = 1382590417,'</p>'; echo '<p>',$szDate = date( 'YmdHis',$iNow ),'</p>'; echo '<p>',$iYear = DAT_Year( $iNow ),'</p>'; echo LSUnitTesting::assert( $iYear === (int) substr( $szDate,0,4 ) , 'ASSERTION SUCCESSFUL: year correctly determined', 'ASSERTION FAILURE: incorrect year' , 'GuideAssert' );
1382590417
20131024045337
2013
GuideAssert() ... ASSERTION SUCCESSFUL: year correctly determined
1 assertions: 1 successful; 0 failed
DATTIME_British()
: Returns the british representation of a date based on $iTime
DATTIME_British( $iTime,$szFormat )
Name | Type | Description |
---|---|---|
$iTime |
int | time() representation |
$szFormat |
string | Optional format of the output. 'm-d-Y H:i:s' by default |
(string) Date representation (Sat 16 June 2012, 16h28 59 sec is represented as '16/06/2012 16:28:59')
echo DATTIME_British( 1339856589 ); // Prints '16/06/2012 14:23:09'
DATTIME_British( 1339856589 ) === '16/06/2012 14:23:09'
successful
1 assertions: 1 successful; 0 failed
DATTIME_French()
, DAT_French()
, DAT_British()
DATTIME_French()
: Returns the french representation of a date based on $iTime
DATTIME_French( $iTime,$szFormat )
Name | Type | Description |
---|---|---|
$iTime |
int | time() representation |
$szFormat |
string | Optional format of the output. 'm-d-Y H:i:s' by default |
(string) Date representation (Sat 16 June 2012, 16h28 59 sec is represented as '16-06-2012 16:28:59')
echo DATTIME_French( 1339856589 ); // Prints '16-06-2012 14:23:09'
DATTIME_French( 1339856589 ) === '16-06-2012 14:23:09'
successful
1 assertions: 1 successful; 0 failed
DAT_French()
, DAT_British()
, DATTIME_British()
IsExpired()
: Determines whether $iNow
is a value that has expired compared to $iExpired
IsExpired( $iNow,$iExpired )
HasExpired()
Name | Type | Description |
---|---|---|
$iNow |
int | Value to compare to |
$iExpired |
int | $iExpired Basis of comparison |
(bool) true if $iNow
> $iExpired
if ( IsExpired( time(),SetExpiry( 2012,12,31,23,59,59 ) ) ) { echo '<p>Expired!</p>'; }
WARNING: No Unit Testing found. Please provide assertions with assertion constructs ({*assert ... *}
) or with GuideAssert()
function calls in exec constructs ({*exec LSUnitTesting::assert(...); *}
).
IsExpired()
, SetExpiry()
, DAT_IsFuture()
, DAT_IsPast()
SetExpiry()
: Returns an integer that represents an expiry expressionDo not use this function to perform EXACT calculation of expiry. However, you can use this function to compare values returned by the same function.
SetExpiry( $iYear,$iMonth,$iDay,$iHours,$iMinutes,$iSeconds )
Name | Type | Description |
---|---|---|
$iYear |
int | Year of expiry |
$iMonth |
int | Month of expiry |
$iDay |
int | Day of expiry |
$iHours |
int | Hour of expiry. Optional. |
$iMinutes |
int | Minute of expiry. Optional. |
$iSeconds |
int | Second of expiry. Optional. |
SetExpiry()
uses 6 parameters whereas the suggested limit is 3.
(int) Expiry date and time turned to an arbitrary integer. However, you can use SetExpiry() return values between themselves
echo '<p>',$iDate1=SetExpiry( 2012,12,31,23,59,59 ),'</p>'; // 1972387238399 echo '<p>',$iDate2=SetExpiry( 2015,1,1 ),'</p>'; // 1975295980800 if ( $iDate2 > $iDate1 ) { echo '<p>$iDate2 > $iDate1</p>'; }
WARNING: No Unit Testing found. Please provide assertions with assertion constructs ({*assert ... *}
) or with GuideAssert()
function calls in exec constructs ({*exec LSUnitTesting::assert(...); *}
).
TIM_2Array()
: Turns a time (HH[:]mm[:]SS) into an associative arrayCreated: 16/06/2012 16:41:18
Since version 5.0.0003
TIM_2Array( $szTime,$szPart )
Name | Type | Description |
---|---|---|
$szTime |
string | A HH[:]mm[:]SS] time string |
$szPart |
string | Optional parameter: the part to be returned - 'hour' : return the hour part as a string- 'min' : return the min part as a string- 'sec' : return the sec part as a string |
(mixed) string if $szPart
is passed; array if $szPart
is not mentioned
Example #1 echo TIM_2Array( '23:50:59','hour' ); // '23' Example #2 echo TIM_2Array( '23:50:59','min' ); // '50' Example #3 echo TIM_2Array( '23:50:59','sec' ); // '59' Example #3 var_dump( TIM_2Array( '14:09:59' ) );
TIM_2Array( '23:50:59','hour' ) == '23'
successful
TIM_2Array( '23:50:59','min' ) == '50'
successful
TIM_2Array( '23:50:59','sec' ) == '59'
successful
STR_Empty( TIM_2Array( '23:50','sec' ) ) == true
successful
4 assertions: 4 successful; 0 failed
TIM_Add()
: Adds a number of seconds to a time stringTIM_Add( $szHour,$iSeconds,$szFormat )
Name | Type | Description |
---|---|---|
$szHour |
string | Hours (HH:MM[:SS] format) |
$iSeconds |
int | Number of seconds to add |
$szFormat |
string | Output format. Optional. 'H:i:s' by default
(see doc of PHP date() function) |
(string) Time string
// From 08:00 to 09:00 (step 15 minutes) --------------- $szTime = '08:00:00'; $iSeconds = 900; // 15 minutes for ( $i = 0;$i < 4;$i++ ) { echo "<p>" . TIM_Add( $szTime,$iSeconds,'H:i' ) . "</p>"; $iSeconds += 900; } echo "<hr style=\"border:none;border-top:1px solid silver;\" />"; // From 08:00 to 07:00 (step -10 minutes) -------------- $szTime = '08:00:00'; $iSeconds = 600; // 10 minutes for ( $i = 0;$i <= 6;$i++ ) { echo "<p>" . TIM_Add( $szTime,-($i * $iSeconds),'H:i' ) . "</p>"; }
08:15
08:30
08:45
09:00
08:00
07:50
07:40
07:30
07:20
07:10
07:00
WARNING: No Unit Testing found. Please provide assertions with assertion constructs ({*assert ... *}
) or with GuideAssert()
function calls in exec constructs ({*exec LSUnitTesting::assert(...); *}
).
TIM_aSlots()
: Returns an array of time slots between $szStart
and $szEnd
($iInterval
seconds for each slot)TIM_aSlots( $szStart,$szEnd,$iInterval,$szFormat )
Name | Type | Description |
---|---|---|
$szStart |
string | Hours (HH:MM[:SS] format) |
$szEnd |
string | Hours (HH:MM[:SS] format) |
$iInterval |
int | Number of seconds for each time slot |
$szFormat |
string | Output format. Optional. 'H:i:s' by default
(see doc of PHP date() function) |
TIM_aSlots()
uses 4 parameters whereas the suggested limit is 3.
(array) Array of time slots ($szFormat
applied)
// From 11:00 to 17:00 (step 20 minutes) --------------- $szStart = '11:00:00'; $szEnd = '17:00:00'; $iInterval = 1200; // 20 minutes $szFormat = 'H:i'; $aSlots = TIM_aSlots( $szStart,$szEnd,$iInterval,$szFormat ); var_dump( $aSlots ); echo LSUnitTesting::assert( count( $aSlots ) === 19 && $aSlots[0] === '11:00' && $aSlots[18] === '17:00' && $aSlots[8] === '13:40' , 'ASSERTION SUCCESSFUL: correct number of slots' , 'ASSERTION FAILURE: incorrect number of slots' , 'GuideAssert' );
array (size=19) 0 => string '11:00' (length=5) 1 => string '11:20' (length=5) 2 => string '11:40' (length=5) 3 => string '12:00' (length=5) 4 => string '12:20' (length=5) 5 => string '12:40' (length=5) 6 => string '13:00' (length=5) 7 => string '13:20' (length=5) 8 => string '13:40' (length=5) 9 => string '14:00' (length=5) 10 => string '14:20' (length=5) 11 => string '14:40' (length=5) 12 => string '15:00' (length=5) 13 => string '15:20' (length=5) 14 => string '15:40' (length=5) 15 => string '16:00' (length=5) 16 => string '16:20' (length=5) 17 => string '16:40' (length=5) 18 => string '17:00' (length=5)GuideAssert() ... ASSERTION SUCCESSFUL: correct number of slots
1 assertions: 1 successful; 0 failed
TIM_Bod()
: Returns a Unix Timestamp for the start of the dayTIM_Bod( $iTime )
Name | Type | Description |
---|---|---|
$iTime |
int | Optional time to consider. Default is time() . |
(int) Start of the day timestamp (identical to time()
)
echo '<p>',date( "d/m/Y H:i:s" ),'</p>'; echo '<p>',date( "d/m/Y H:i:s",TIM_Bod() ),'</p>'; echo '<p>',date( "d/m/Y H:i:s",TIM_Bod( time() - ( 4 * 86400 ) ) ),'</p>';
01/04/2015 16:19:49
01/04/2015 00:00:00
28/03/2015 00:00:00
TIM_Bod( 1390303904 ) === 1390262400
successful
1 assertions: 1 successful; 0 failed
TIM_Diff()
: Computes the time difference in seconds between $szDT1
and $szDT2
Created: 03/08/2012 21:30:51
Since version 5.0.0006
TIM_Diff( $szDT1,$szDT2 )
Name | Type | Description |
---|---|---|
$szDT1 |
string | Date time expression (YYYYMMDD[HH:mm:SS]) |
$szDT2 |
string | Date time expression (YYYYMMDD[HH:mm:SS]) |
(int) Time difference between $szDT1
and $szDT2
(expressed in
seconds)
TIM_Diff("07:30","08:15") === 2700
successful
TIM_Diff("08:15","07:30") === -2700
successful
2 assertions: 2 successful; 0 failed
TIM_Int2Time()
: Turns a unumber of seconds (integer) to a string representationTIM_Int2Time( $iSecs )
Name | Type | Description |
---|---|---|
$iSecs |
int | The number of seconds to turn to a time string |
(string) Time string
echo '<p>2700 sec (45 min) = ' ,TIM_Int2Time(2700),'</p>'; echo '<p>-2700 sec (45 min) = ' ,TIM_Int2Time(-2700),'</p>'; echo '<p>3600 sec (1 hour) = ' ,TIM_Int2Time(3600),'</p>'; echo '<p>2700000 sec (750 hours) = ',TIM_Int2Time(2700000),'</p>';
2700 sec (45 min) = 00:45:00
-2700 sec (45 min) = 00:45:00
3600 sec (1 hour) = 01:00:00
2700000 sec (750 hours) = 750:00:00
TIM_Int2Time( 2701 ) === '00:45:01'
successful
1 assertions: 1 successful; 0 failed
TIM_IsBetween()
: Determines whether $iNow
is between $szStart
and $szStop
TIM_IsBetween( $iNow,$szStart,$szStop )
Name | Type | Description |
---|---|---|
$iNow |
int | Value to compare |
$szStart |
string | Time interval start value (HH:MM:SS) |
$szStop |
string | Time interval stop value (HH:MM:SS) |
(bool) true if $szStart
<= $iNow
<= $szStop
; false otherwise
if ( TIM_IsBetween( time(),'12:00:00','13:00:00' ) ) { echo '<p>Lunch time!</p>'; }
WARNING: No Unit Testing found. Please provide assertions with assertion constructs ({*assert ... *}
) or with GuideAssert()
function calls in exec constructs ({*exec LSUnitTesting::assert(...); *}
).
TIM_MakeInt()
: Transforms a DTOS value (YYYYMMDD) into an integerTIM_MakeInt( $szDTOS )
Name | Type | Description |
---|---|---|
$szDTOS |
string | Optional time (same format as time() ).
If not passed, the current time is considered |
(int) $szDTOS
(YYYYMMDD) turned to an integer
echo '<p>',TIM_MakeInt( "20120512" ),'</p>'; // 1336780800 echo '<p>',date( 'Ymd',1336780800 ),'</p>'; // 20120512
WARNING: No Unit Testing found. Please provide assertions with assertion constructs ({*assert ... *}
) or with GuideAssert()
function calls in exec constructs ({*exec LSUnitTesting::assert(...); *}
).
TIM_Stot()
: Creates a time value (time()
) from a YYYYMMDDHHmmSS
valueTIM_Stot( $szYYYYMMDDHHmmSS )
DAT_Stot(), DAT_Stod()
Name | Type | Description |
---|---|---|
$szYYYYMMDDHHmmSS |
string | Time string (YYYYMM[DD[HH[mm[SS]]]] ) |
(int) Time value of $szYYYYMMDDHHmmSS
echo TIM_Stot( '20120512164800' ); // 1336841280 echo date( 'YmdHis',1336841280 ); // 20120512164800
echo "<p>",( $iTime = TIM_Stot( '20130203155959') ),' - ',date( 'd-m-Y H:i:s',$iTime ),"</p>"; echo "<p>",( $iTime = TIM_Stot( '201302031559' ) ),' - ',date( 'd-m-Y H:i:s',$iTime ),"</p>"; echo "<p>",( $iTime = TIM_Stot( '2013020315' ) ),' - ',date( 'd-m-Y H:i:s',$iTime ),"</p>"; echo "<p>",( $iTime = TIM_Stot( '20130203' ) ),' - ',date( 'd-m-Y H:i:s',$iTime ),"</p>"; echo "<p>",( $iTime = TIM_Stot( '201302' ) ),' - ',date( 'd-m-Y H:i:s',$iTime ),"</p>"; echo "<p>",( $iTime = TIM_Stot( 'hello' ) ) ,"</p>";
1359907199 - 03-02-2013 15:59:59
1359907140 - 03-02-2013 15:59:00
1359903600 - 03-02-2013 15:00:00
1359849600 - 03-02-2013 00:00:00
1359676800 - 01-02-2013 00:00:00
-1
date( 'd-m-Y H:i:s',TIM_Stot( '20130203155959') ) === '03-02-2013 15:59:59'
successful
date( 'd-m-Y H:i:s',TIM_Stot( '201302031559' ) ) === '03-02-2013 15:59:00'
successful
date( 'd-m-Y H:i:s',TIM_Stot( '2013020315' ) ) === '03-02-2013 15:00:00'
successful
date( 'd-m-Y H:i:s',TIM_Stot( '20130203' ) ) === '03-02-2013 00:00:00'
successful
date( 'd-m-Y H:i:s',TIM_Stot( '201302' ) ) === '01-02-2013 00:00:00'
successful
TIM_Stot( 'hello' ) === -1
successful
6 assertions: 6 successful; 0 failed
TIM_Time2Int()
: Turns a time representation (string) into an integerTIM_Time2Int( $szHour )
Name | Type | Description |
---|---|---|
$szHour |
string | Time string (e.g. "09:14:25" or "09:14" or "09" or "9") |
(int) $szHour
turned to an integer
echo '<p>00:00 = ',TIM_Time2Int('00:00'),'</p>'; echo '<p>01:20 = ',TIM_Time2Int('01:20'),'</p>'; echo '<p>15:17 = ',TIM_Time2Int('15:17'),'</p>';
00:00 = 0
01:20 = 4800
15:17 = 55020
TIM_Time2Int('15') === 15 * 3600
successful
TIM_Time2Int('00:13') === 13 * 60
successful
TIM_Time2Int('15:17') === 15 * 3600 + 17 * 60
successful
TIM_Time2Int('15:17:43') === 15 * 3600 + 17 * 60 + 43
successful
4 assertions: 4 successful; 0 failed