| 
									
										
										
										
											2008-10-06 19:18:33 -04:00
										 |  |  | ! Copyright (C) 2008 Doug Coleman. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2008-10-06 18:59:20 -04:00
										 |  |  | USING: alien alien.c-types alien.syntax arrays calendar | 
					
						
							| 
									
										
										
										
											2009-08-30 05:06:41 -04:00
										 |  |  | kernel math unix unix.time unix.types namespaces system | 
					
						
							|  |  |  | accessors classes.struct ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | IN: calendar.unix | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-13 19:24:48 -04:00
										 |  |  | : timeval>duration ( timeval -- duration )
 | 
					
						
							| 
									
										
										
										
											2009-08-30 05:06:41 -04:00
										 |  |  |     [ sec>> seconds ] [ usec>> microseconds ] bi time+ ;
 | 
					
						
							| 
									
										
										
										
											2008-10-21 05:19:50 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : timeval>unix-time ( timeval -- timestamp )
 | 
					
						
							| 
									
										
										
										
											2010-06-13 19:24:48 -04:00
										 |  |  |     timeval>duration since-1970 ;
 | 
					
						
							| 
									
										
										
										
											2008-10-06 19:03:56 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-18 16:27:02 -04:00
										 |  |  | : timespec>duration ( timespec -- seconds )
 | 
					
						
							| 
									
										
										
										
											2009-08-30 05:06:41 -04:00
										 |  |  |     [ sec>> seconds ] [ nsec>> nanoseconds ] bi time+ ;
 | 
					
						
							| 
									
										
										
										
											2008-10-21 05:19:50 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-15 01:46:12 -05:00
										 |  |  | : timespec>nanoseconds ( timespec -- seconds )
 | 
					
						
							|  |  |  |     [ sec>> 1000000000 * ] [ nsec>> ] bi + ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-21 05:19:50 -04:00
										 |  |  | : timespec>unix-time ( timespec -- timestamp )
 | 
					
						
							| 
									
										
										
										
											2010-07-18 16:27:02 -04:00
										 |  |  |     timespec>duration since-1970 ;
 | 
					
						
							| 
									
										
										
										
											2008-10-06 19:03:56 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-19 20:15:32 -04:00
										 |  |  | : get-time ( -- alien )
 | 
					
						
							| 
									
										
										
										
											2010-02-22 15:22:29 -05:00
										 |  |  |     f time <time_t> localtime ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-19 20:15:32 -04:00
										 |  |  | : timezone-name ( -- string )
 | 
					
						
							| 
									
										
										
										
											2009-08-30 05:06:41 -04:00
										 |  |  |     get-time zone>> ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-02 19:28:55 -04:00
										 |  |  | M: unix gmt-offset ( -- hours minutes seconds )
 | 
					
						
							| 
									
										
										
										
											2009-08-30 05:06:41 -04:00
										 |  |  |     get-time gmtoff>> 3600 /mod 60 /mod ;
 | 
					
						
							| 
									
										
										
										
											2010-06-17 01:04:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-22 02:49:11 -04:00
										 |  |  | : current-timeval ( -- timeval )
 | 
					
						
							|  |  |  |     timeval <struct> f [ gettimeofday io-error ] 2keep drop ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : system-micros ( -- n )
 | 
					
						
							|  |  |  |     current-timeval | 
					
						
							|  |  |  |     [ sec>> 1,000,000 * ] [ usec>> ] bi + ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-17 01:04:53 -04:00
										 |  |  | M: unix gmt | 
					
						
							| 
									
										
										
										
											2010-06-22 02:49:11 -04:00
										 |  |  |     current-timeval timeval>unix-time ;
 |