523
|
1 // timefns.cc -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993, 1994 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
|
26 #endif |
|
27 |
|
28 #include <time.h> |
|
29 |
|
30 #include "dMatrix.h" |
|
31 |
|
32 #include "tree-const.h" |
|
33 #include "oct-obj.h" |
|
34 #include "defun.h" |
|
35 |
|
36 DEFUN ("clock", Fclock, Sclock, 1, 0, |
|
37 "clock (): return current date and time in vector with elements\n\ |
|
38 \n\ |
|
39 [ year, month, day-of-month, hour, minute, second ]") |
|
40 { |
|
41 time_t now; |
|
42 struct tm *tm; |
|
43 |
|
44 time (&now); |
|
45 tm = localtime (&now); |
|
46 |
|
47 Matrix m (1, 6); |
|
48 m.elem (0, 0) = tm->tm_year + 1900; |
|
49 m.elem (0, 1) = tm->tm_mon + 1; |
|
50 m.elem (0, 2) = tm->tm_mday; |
|
51 m.elem (0, 3) = tm->tm_hour; |
|
52 m.elem (0, 4) = tm->tm_min; |
|
53 m.elem (0, 5) = tm->tm_sec; |
|
54 |
|
55 return m; |
|
56 } |
|
57 |
|
58 DEFUN ("date", Fdate, Sdate, 1, 0, |
|
59 "date (): return current date in a string, in the form `18-Jul-94'") |
|
60 { |
|
61 Octave_object retval; |
|
62 |
|
63 time_t now; |
|
64 struct tm *tm; |
|
65 |
|
66 time (&now); |
|
67 tm = localtime (&now); |
|
68 char date[32]; |
|
69 int len = strftime (date, 31, "%d-%b-%y", tm); |
|
70 if (len > 0) |
|
71 retval = date; |
|
72 |
|
73 return retval; |
|
74 } |
|
75 |
|
76 /* |
|
77 ;;; Local Variables: *** |
|
78 ;;; mode: C++ *** |
|
79 ;;; page-delimiter: "^/\\*" *** |
|
80 ;;; End: *** |
|
81 */ |