File modules/dsl/standard/DateWrapper.class.php

Last commit: Tue Jul 19 00:10:00 2022 +0200	Jan Dankert	New: Scripting language: Ignore Keyword "new"; Support for Calling object constructors; Splitting objects into an instance and a wrapper.
1 <?php 2 namespace dsl\standard; 3 4 use dsl\context\BaseScriptableObject; 5 6 class DateWrapper extends BaseScriptableObject 7 { 8 /** 9 * Date.now() 10 * 11 * milliseconds since 1970. 12 * 13 * @return int 14 */ 15 public function now() { 16 17 return floor(microtime(true) * 1000); 18 } 19 20 21 /** 22 * @param int $year year 23 * @param int $month month 0-based 24 * @param int $day day of month 25 * @param int $hour hour 26 * @param int $minute minute 27 * @param int $second second 28 * @return DateInstance 29 */ 30 public function __invoke( $year = 0,$month = 0,$day = 0,$hour = 0,$minute = 0,$second = 0 ) 31 { 32 if ( is_string($year) ) 33 return new DateInstance( strtotime($year) ); 34 35 if ( is_numeric($year) && $year && !$month ) 36 return new DateInstance( floor($year/1000) ); 37 38 $month++; // month in JS is 0-based, but in PHP 1-based. 39 40 if ( is_numeric($year) && $year ) 41 return new DateInstance( mktime( $hour, $minute, $second, $month, $day, $year ) ); 42 43 return new DateInstance(); 44 } 45 46 /** 47 * Gets the current date object. 48 * @return DateInstance 49 */ 50 public function getDate( $date = null ) { 51 52 return new DateInstance( $date ); 53 } 54 55 56 57 public function __toString() 58 { 59 return "Date"; 60 } 61 62 public function help() 63 { 64 return Helper::getHelp($this); 65 } 66 67 68 public function parse( $dateAsString ) { 69 70 return strtotime( $dateAsString ) * 1000; 71 } 72 }
Download modules/dsl/standard/DateWrapper.class.php
History Tue, 19 Jul 2022 00:10:00 +0200 Jan Dankert New: Scripting language: Ignore Keyword "new"; Support for Calling object constructors; Splitting objects into an instance and a wrapper.