2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
5 Query the current time and/or timezone.
8 #include "__arosc_privdata.h"
10 #include <proto/exec.h>
11 #include <proto/dos.h>
12 #include <proto/timer.h>
13 #include <proto/locale.h>
14 #include <exec/types.h>
15 #include <devices/timer.h>
16 #include <aros/symbolsets.h>
17 #include <aros/debug.h>
22 struct Device
*TimerBase
;
23 static void __init_timerbase(void);
25 /*****************************************************************************
38 Return the current time and/or timezone.
41 tv - If this pointer is non-NULL, the current time will be
42 stored here. The structure looks like this:
46 long tv_sec; // seconds
47 long tv_usec; // microseconds
50 tz - If this pointer is non-NULL, the current timezone will be
51 stored here. The structure looks like this:
55 int tz_minuteswest; // minutes west of Greenwich
56 int tz_dsttime; // type of dst correction
59 With daylight savings times defined as follows :
61 DST_NONE // not on dst
62 DST_USA // USA style dst
63 DST_AUST // Australian style dst
64 DST_WET // Western European dst
65 DST_MET // Middle European dst
66 DST_EET // Eastern European dst
68 DST_GB // Great Britain and Eire
71 DST_AUSTALT // Australian style with shift in 1986
73 And the following macros are defined to operate on this :
75 timerisset(tv) - TRUE if tv contains a time
77 timercmp(tv1, tv2, cmp) - Return the result of the
78 comparison "tv1 cmp tv2"
80 timerclear(tv) - Clear the timeval struct
83 The number of seconds.
86 This function must not be used in a shared library or
87 in a threaded application.
92 // Get the current time and print it
93 gettimeofday (&tv, NULL);
95 printf ("Seconds = %ld, uSec = %ld\n", tv->tv_sec, tv->tv_usec);
100 ctime(), asctime(), localtime(), time()
104 ******************************************************************************/
115 /* Adjust with the current timezone, stored in minutes west of GMT */
116 tv
->tv_sec
+= (2922 * 1440 + __arosc_gmtoffset()) * 60;
127 tz
->tz_minuteswest
= __arosc_gmtoffset();
128 /* FIXME: set tz->tz_dsttime */
129 tz
->tz_dsttime
= DST_NONE
;
136 static struct timerequest __timereq
;
137 static struct MsgPort __timeport
;
139 static void __init_timerbase(void)
141 __timeport
.mp_Node
.ln_Type
= NT_MSGPORT
;
142 __timeport
.mp_Node
.ln_Pri
= 0;
143 __timeport
.mp_Node
.ln_Name
= NULL
;
144 __timeport
.mp_Flags
= PA_IGNORE
;
145 __timeport
.mp_SigTask
= FindTask(NULL
);
146 __timeport
.mp_SigBit
= 0;
147 NEWLIST(&__timeport
.mp_MsgList
);
149 __timereq
.tr_node
.io_Message
.mn_Node
.ln_Type
= NT_MESSAGE
;
150 __timereq
.tr_node
.io_Message
.mn_Node
.ln_Pri
= 0;
151 __timereq
.tr_node
.io_Message
.mn_Node
.ln_Name
= NULL
;
152 __timereq
.tr_node
.io_Message
.mn_ReplyPort
= &__timeport
;
153 __timereq
.tr_node
.io_Message
.mn_Length
= sizeof (__timereq
);
161 (struct IORequest
*)&__timereq
,
168 TimerBase
= (struct Device
*)__timereq
.tr_node
.io_Device
;
173 static void __exit_timerbase(APTR dummy
)
175 if (TimerBase
!= NULL
)
176 CloseDevice((struct IORequest
*)&__timereq
);
179 ADD2EXIT(__exit_timerbase
, 0);