1 21 22 package org.armedbear.lisp; 23 24 import java.util.Date ; 25 import java.util.TimeZone ; 26 27 public final class Time extends Lisp 28 { 29 private static final Primitive1 _TIME = 31 new Primitive1("%time", PACKAGE_SYS, false) 32 { 33 public LispObject execute(LispObject arg) throws ConditionThrowable 34 { 35 Cons.setCount(0); 36 long start = System.currentTimeMillis(); 37 LispObject result = arg.execute(new LispObject[0]); 38 long elapsed = System.currentTimeMillis() - start; 39 long count = Cons.getCount(); 40 Stream out = 41 checkCharacterOutputStream(_TRACE_OUTPUT_.symbolValue()); 42 out.freshLine(); 43 StringBuffer sb = 44 new StringBuffer (String.valueOf((float)elapsed/1000)); 45 sb.append(" seconds"); 46 sb.append(System.getProperty("line.separator")); 47 if (count > 0) { 48 sb.append(count); 49 sb.append(" cons cell"); 50 if (count > 1) 51 sb.append('s'); 52 sb.append(System.getProperty("line.separator")); 53 } 54 out._writeString(sb.toString()); 55 out._finishOutput(); 56 return result; 57 } 58 }; 59 60 private static final Primitive0 GET_INTERNAL_REAL_TIME = 62 new Primitive0("get-internal-real-time","") { 63 public LispObject execute() throws ConditionThrowable 64 { 65 return number(System.currentTimeMillis()); 66 } 67 }; 68 69 private static final Primitive0 GET_INTERNAL_RUN_TIME = 71 new Primitive0("get-internal-run-time","") { 72 public LispObject execute() throws ConditionThrowable 73 { 74 return number(System.currentTimeMillis()); } 76 }; 77 78 private static final Primitive0 GET_UNIVERSAL_TIME = 80 new Primitive0("get-universal-time","") { 81 public LispObject execute() 82 { 83 return number(System.currentTimeMillis() / 1000 + 2208988800L); 84 } 85 }; 86 87 private static final Primitive0 DEFAULT_TIME_ZONE = 89 new Primitive0("default-time-zone", PACKAGE_SYS, false) 90 { 91 public LispObject execute() throws ConditionThrowable 92 { 93 TimeZone tz = TimeZone.getDefault(); 94 int rawOffset = tz.getRawOffset(); 97 if (tz.inDaylightTime(new Date (System.currentTimeMillis()))) 98 rawOffset += tz.getDSTSavings(); 99 return new Fixnum(- rawOffset).divideBy(new Fixnum(3600000)); 102 } 103 }; 104 } 105 | Popular Tags |