| 
									
										
										
										
											2008-03-04 23:32:12 -05:00
										 |  |  | ! Copyright (C) 2007 Doug Coleman. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2012-07-16 18:46:52 -04:00
										 |  |  | USING: accessors alien alien.c-types calendar calendar.private | 
					
						
							|  |  |  | classes.struct kernel math math.bitwise namespaces | 
					
						
							|  |  |  | windows.errors windows.handles windows.kernel32 windows.types ;
 | 
					
						
							| 
									
										
										
										
											2008-03-04 23:32:12 -05:00
										 |  |  | IN: windows.time | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : >64bit ( lo hi -- n )
 | 
					
						
							| 
									
										
										
										
											2009-04-30 10:36:25 -04:00
										 |  |  |     32 shift bitor ; inline
 | 
					
						
							| 
									
										
										
										
											2008-03-04 23:32:12 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-14 18:20:30 -05:00
										 |  |  | : windows-1601 ( -- timestamp ) 1601 <year-gmt> ;
 | 
					
						
							| 
									
										
										
										
											2008-03-04 23:32:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : FILETIME>windows-time ( FILETIME -- n )
 | 
					
						
							| 
									
										
										
										
											2009-08-25 18:34:06 -04:00
										 |  |  |     [ dwLowDateTime>> ] [ dwHighDateTime>> ] bi >64bit ;
 | 
					
						
							| 
									
										
										
										
											2008-03-04 23:32:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : windows-time>timestamp ( n -- timestamp )
 | 
					
						
							| 
									
										
										
										
											2012-07-16 18:30:58 -04:00
										 |  |  |     [ windows-1601 ] dip 10,000,000 /i +second ;
 | 
					
						
							| 
									
										
										
										
											2008-03-04 23:32:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : windows-time ( -- n )
 | 
					
						
							| 
									
										
										
										
											2009-08-25 18:34:06 -04:00
										 |  |  |     FILETIME <struct> [ GetSystemTimeAsFileTime ] keep
 | 
					
						
							| 
									
										
										
										
											2008-03-04 23:32:12 -05:00
										 |  |  |     FILETIME>windows-time ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : timestamp>windows-time ( timestamp -- n )
 | 
					
						
							|  |  |  |     #! 64bit number representing # of nanoseconds since Jan 1, 1601 (UTC) | 
					
						
							| 
									
										
										
										
											2012-07-16 18:30:58 -04:00
										 |  |  |     >gmt windows-1601 (time-) 10,000,000 * >integer ;
 | 
					
						
							| 
									
										
										
										
											2008-03-04 23:32:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : windows-time>FILETIME ( n -- FILETIME )
 | 
					
						
							| 
									
										
										
										
											2009-08-25 18:34:06 -04:00
										 |  |  |     [ FILETIME <struct> ] dip
 | 
					
						
							|  |  |  |     [ 32 bits >>dwLowDateTime ] [ -32 shift >>dwHighDateTime ] bi ;
 | 
					
						
							| 
									
										
										
										
											2008-03-04 23:32:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : timestamp>FILETIME ( timestamp -- FILETIME/f )
 | 
					
						
							| 
									
										
										
										
											2008-12-15 04:47:13 -05:00
										 |  |  |     dup [ >gmt timestamp>windows-time windows-time>FILETIME ] when ;
 | 
					
						
							| 
									
										
										
										
											2008-03-04 23:32:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : FILETIME>timestamp ( FILETIME -- timestamp/f )
 | 
					
						
							|  |  |  |     FILETIME>windows-time windows-time>timestamp ;
 |