| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 | /* * Copyright (C)2005-2013 Haxe Foundation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ /**	The Date class provides a basic structure for date and time related	information. Date instances can be created by	- `new Date()` for a specific date,	- `Date.now()` to obtain information about the current time,	- `Date.fromTime()` with a given timestamp or	- `Date.fromString()` by parsing from a String.	There is some extra functions available in the `DateTools` class.	In the context of haxe dates, a timestamp is defined as the number of	milliseconds elapsed since 1st January 1970.**/extern class Date{	/**		Creates a new date object from the given arguments.		The behaviour of a Date instance is only consistent across platforms if		the the arguments describe a valid date.		- month: 0 to 11		- day: 1 to 31		- hour: 0 to 23		- min: 0 to 59		- sec: 0 to 59	**/	function new(year : Int, month : Int, day : Int, hour : Int, min : Int, sec : Int ) : Void;	/**		Returns the timestamp of the date. It might only have a per-second		precision depending on the platforms.	**/	function getTime() : Float;	/**		Returns the hours of `this` Date (0-23 range).	**/	function getHours() : Int;	/**		Returns the minutes of `this` Date (0-59 range).	**/	function getMinutes() : Int;	/**		Returns the seconds of the `this` Date (0-59 range).	**/	function getSeconds() : Int;	/**		Returns the full year of `this` Date (4-digits).	**/	function getFullYear() : Int;	/**		Returns the month of `this` Date (0-11 range).	**/	function getMonth() : Int;	/**		Returns the day of `this` Date (1-31 range).	**/	function getDate() : Int;	/**		Returns the day of the week of `this` Date (0-6 range).	**/	function getDay() : Int;	/**		Returns a string representation of `this` Date, by using the		standard format [YYYY-MM-DD HH:MM:SS]. See `DateTools.format` for		other formating rules.	**/	function toString():String;	/**		Returns a Date representing the current local time.	**/	static function now() : Date;	/**		Returns a Date from timestamp `t`.	**/	static function fromTime( t : Float ) : Date;	/**		Returns a Date from a formated string `s`, with the following accepted		formats:		- `"YYYY-MM-DD hh:mm:ss"`		- `"YYYY-MM-DD"`		- `"hh:mm:ss"`		The first two formats are expressed in local time, the third in UTC		Epoch.	**/	static function fromString( s : String ) : Date;#if flash	private static function __init__() : Void untyped {		var d #if !swf_mark : Dynamic #end = Date;		d.now = function() {			return __new__(Date);		};		d.fromTime = function(t){			var d : Date = __new__(Date);			#if flash9			d.setTime(t);			#else			d["setTime"]( t );			#end			return d;		};		d.fromString = function(s : String) {			switch( s.length ) {			case 8: // hh:mm:ss				var k = s.split(":");				var d : Date = __new__(Date);				#if flash9				d.setTime(0);				d.setUTCHours(k[0]);				d.setUTCMinutes(k[1]);				d.setUTCSeconds(k[2]);				#else				d["setTime"](0);				d["setUTCHours"](k[0]);				d["setUTCMinutes"](k[1]);				d["setUTCSeconds"](k[2]);				#end				return d;			case 10: // YYYY-MM-DD				var k = s.split("-");				return new Date(cast k[0],cast k[1] - 1,cast k[2],0,0,0);			case 19: // YYYY-MM-DD hh:mm:ss				var k = s.split(" ");				var y = k[0].split("-");				var t = k[1].split(":");				return new Date(cast y[0],cast y[1] - 1,cast y[2],cast t[0],cast t[1],cast t[2]);			default:				throw "Invalid date format : " + s;			}		};		d.prototype[#if (as3 || no_flash_override) "toStringHX" #else "toString" #end] = function() {			var date : Date = __this__;			var m = date.getMonth() + 1;			var d = date.getDate();			var h = date.getHours();			var mi = date.getMinutes();			var s = date.getSeconds();			return date.getFullYear()				+"-"+(if( m < 10 ) "0"+m else ""+m)				+"-"+(if( d < 10 ) "0"+d else ""+d)				+" "+(if( h < 10 ) "0"+h else ""+h)				+":"+(if( mi < 10 ) "0"+mi else ""+mi)				+":"+(if( s < 10 ) "0"+s else ""+s);		};		#if flash9		#elseif flash		d.prototype[__unprotect__("__class__")] = d;		d[__unprotect__("__name__")] = ["Date"];		#end	}#end}
 |