1 /* glpenv06.c (standard time) */
3 /***********************************************************************
4 * This code is part of GLPK (GNU Linear Programming Kit).
6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
7 * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
9 * E-mail: <mao@gnu.org>.
11 * GLPK is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * GLPK is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 * License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
23 ***********************************************************************/
31 /***********************************************************************
34 * glp_time - determine current universal time
38 * glp_long glp_time(void);
42 * The routine glp_time returns the current universal time (UTC), in
43 * milliseconds, elapsed since 00:00:00 GMT January 1, 1970. */
45 static const int epoch = 2440588; /* = jday(1, 1, 1970) */
47 /* POSIX version ******************************************************/
49 #if defined(HAVE_SYS_TIME_H) && defined(HAVE_GETTIMEOFDAY)
54 glp_long glp_time(void)
59 gettimeofday(&tv, NULL);
60 tm = gmtime(&tv.tv_sec);
61 j = jday(tm->tm_mday, tm->tm_mon + 1, 1900 + tm->tm_year);
64 t = xlmul(t, xlset(24));
65 t = xladd(t, xlset(tm->tm_hour));
66 t = xlmul(t, xlset(60));
67 t = xladd(t, xlset(tm->tm_min));
68 t = xlmul(t, xlset(60));
69 t = xladd(t, xlset(tm->tm_sec));
70 t = xlmul(t, xlset(1000));
71 t = xladd(t, xlset(tv.tv_usec / 1000));
75 /* Windows version ****************************************************/
77 #elif defined(__WOE__)
81 glp_long glp_time(void)
86 j = jday(st.wDay, st.wMonth, st.wYear);
89 t = xlmul(t, xlset(24));
90 t = xladd(t, xlset(st.wHour));
91 t = xlmul(t, xlset(60));
92 t = xladd(t, xlset(st.wMinute));
93 t = xlmul(t, xlset(60));
94 t = xladd(t, xlset(st.wSecond));
95 t = xlmul(t, xlset(1000));
96 t = xladd(t, xlset(st.wMilliseconds));
100 /* portable ISO C version *********************************************/
106 glp_long glp_time(void)
113 j = jday(tm->tm_mday, tm->tm_mon + 1, 1900 + tm->tm_year);
115 t = xlset(j - epoch);
116 t = xlmul(t, xlset(24));
117 t = xladd(t, xlset(tm->tm_hour));
118 t = xlmul(t, xlset(60));
119 t = xladd(t, xlset(tm->tm_min));
120 t = xlmul(t, xlset(60));
121 t = xladd(t, xlset(tm->tm_sec));
122 t = xlmul(t, xlset(1000));
128 /***********************************************************************
131 * glp_difftime - compute difference between two time values
135 * double glp_difftime(glp_long t1, glp_long t0);
139 * The routine glp_difftime returns the difference between two time
140 * values t1 and t0, expressed in seconds. */
142 double glp_difftime(glp_long t1, glp_long t0)
144 xltod(xlsub(t1, t0)) / 1000.0;
147 /**********************************************************************/
153 int ttt, ss, mm, hh, day, month, year;
156 xprintf("t = %s\n", xltoa(t, s));
157 d = xldiv(t, xlset(1000));
158 ttt = d.rem.lo, t = d.quot;
159 d = xldiv(t, xlset(60));
160 ss = d.rem.lo, t = d.quot;
161 d = xldiv(t, xlset(60));
162 mm = d.rem.lo, t = d.quot;
163 d = xldiv(t, xlset(24));
164 hh = d.rem.lo, t = d.quot;
165 xassert(jdate(t.lo + epoch, &day, &month, &year) == 0);
166 xprintf("%04d-%02d-%02d %02d:%02d:%02d.%03d\n", year, month, day,