source: branches/0.17.x/abcl/src/org/armedbear/lisp/Time.java

Last change on this file was 12254, checked in by ehuelsmann, 16 years ago

Remove 'throws ConditionThrowable?' method annotations:

it's an unchecked exception now, so no need to declare it thrown.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
1/*
2 * Time.java
3 *
4 * Copyright (C) 2003-2005 Peter Graves
5 * $Id: Time.java 12254 2009-11-06 20:07:54Z ehuelsmann $
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 *
21 * As a special exception, the copyright holders of this library give you
22 * permission to link this library with independent modules to produce an
23 * executable, regardless of the license terms of these independent
24 * modules, and to copy and distribute the resulting executable under
25 * terms of your choice, provided that you also meet, for each linked
26 * independent module, the terms and conditions of the license of that
27 * module.  An independent module is a module which is not derived from
28 * or based on this library.  If you modify this library, you may extend
29 * this exception to your version of the library, but you are not
30 * obligated to do so.  If you do not wish to do so, delete this
31 * exception statement from your version.
32 */
33
34package org.armedbear.lisp;
35
36import java.lang.reflect.Method;
37import java.util.Date;
38import java.util.TimeZone;
39
40public final class Time extends Lisp
41{
42
43  // ### %time
44  private static final Primitive _TIME =
45    new Primitive("%time", PACKAGE_SYS, false)
46    {
47      @Override
48      public LispObject execute(LispObject arg)
49      {
50        Cons.setCount(0);
51        long realStart = System.currentTimeMillis();
52        try
53          {
54            return arg.execute();
55          }
56        finally
57          {
58            long realElapsed = System.currentTimeMillis() - realStart;
59            long count = Cons.getCount();
60            Stream out =
61              checkCharacterOutputStream(Symbol.TRACE_OUTPUT.symbolValue());
62            out.freshLine();
63            FastStringBuffer sb = new FastStringBuffer();
64            sb.append(String.valueOf((float)realElapsed / 1000));
65            sb.append(" seconds real time");
66            sb.append(System.getProperty("line.separator"));
67            sb.append(count);
68            sb.append(" cons cell");
69            if (count != 1)
70              sb.append('s');
71            sb.append(System.getProperty("line.separator"));
72            out._writeString(sb.toString());
73            out._finishOutput();
74          }
75      }
76    };
77
78  // ### get-internal-real-time
79  private static final Primitive GET_INTERNAL_REAL_TIME =
80    new Primitive("get-internal-real-time", "")
81    {
82      @Override
83      public LispObject execute()
84      {
85        return number(System.currentTimeMillis());
86      }
87    };
88
89  // ### get-internal-run-time
90  private static final Primitive GET_INTERNAL_RUN_TIME =
91    new Primitive("get-internal-run-time", "")
92    {
93      @Override
94      public LispObject execute()
95      {
96        return number(System.currentTimeMillis());
97      }
98    };
99
100  // ### get-universal-time
101  private static final Primitive GET_UNIVERSAL_TIME =
102    new Primitive("get-universal-time", "")
103    {
104      @Override
105      public LispObject execute()
106      {
107        return number(System.currentTimeMillis() / 1000 + 2208988800L);
108      }
109    };
110
111  // ### default-time-zone => offset daylight-p
112  private static final Primitive DEFAULT_TIME_ZONE =
113    new Primitive("default-time-zone", PACKAGE_SYS, false)
114    {
115      @Override
116      public LispObject execute()
117      {
118        TimeZone tz = TimeZone.getDefault();
119        //int offset = tz.getOffset(System.currentTimeMillis());
120        // Classpath hasn't implemented TimeZone.getOffset(long).
121        int rawOffset = tz.getRawOffset();
122        final boolean inDaylightTime =
123          tz.inDaylightTime(new Date(System.currentTimeMillis()));
124        if (inDaylightTime)
125          rawOffset += tz.getDSTSavings();
126        // "Time zone values increase with motion to the west..."
127        // Convert milliseconds to hours.
128        return LispThread.currentThread().setValues(
129          Fixnum.getInstance(- rawOffset).divideBy(Fixnum.getInstance(3600000)),
130          inDaylightTime ? T : NIL);
131      }
132    };
133}
Note: See TracBrowser for help on using the repository browser.