1 /* Copyright (C) 1998, 1999 Red Hat, Inc.
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
11 // We want to make sure to pick up the POSIX `_r' functions. Some
12 // systems, such as Solaris 2.6, require this define in order to
13 // declare the functions in the appropriate header.
14 #if defined (HAVE_GMTIME_R) || defined (HAVE_LOCALTIME_R)
15 # define _POSIX_PTHREAD_SEMANTICS
18 # endif /* _REENTRANT */
26 #include <java/util/TimeZone.h>
27 #include <java/util/GregorianCalendar.h>
31 java::util::GregorianCalendar::computeTime ()
34 tim
.tm_sec
= elements(fields
)[SECOND
];
35 tim
.tm_min
= elements(fields
)[MINUTE
];
36 tim
.tm_hour
= elements(fields
)[HOUR_OF_DAY
];
37 tim
.tm_mday
= elements(fields
)[DATE
];
38 tim
.tm_mon
= elements(fields
)[MONTH
];
39 tim
.tm_year
= elements(fields
)[YEAR
] - 1900;
40 tim
.tm_isdst
= 0; // FIXME
42 // FIXME: None of the standard C library access to the ECOS calendar
44 time_t t
= mktime (&tim
);
49 // Adjust for local timezone (introduced by mktime) and our
51 #if defined (STRUCT_TM_HAS_GMTOFF)
53 #elif defined (HAVE_TIMEZONE)
56 java::util::TimeZone
*zone
= getTimeZone ();
57 t
+= zone
->getRawOffset();
59 // Adjust for milliseconds.
60 time
= t
* (jlong
) 1000 + elements(fields
)[MILLISECOND
];
66 java::util::GregorianCalendar::computeFields ()
68 time_t t
= time
/ 1000;
69 int millis
= time
% 1000;
70 if (t
< 0 && millis
!= 0)
73 millis
= t
- 1000 * t
;
75 elements(fields
)[MILLISECOND
] = millis
;
77 java::util::TimeZone
*zone
= getTimeZone ();
79 // FIXME: None of the standard C library access to the ECOS calendar
82 memset (&tim
, 0, sizeof tim
);
84 if (zone
->getRawOffset() == 0 || ! zone
->useDaylightTime())
86 #if defined(__JV_POSIX_THREADS__) && defined(HAVE_GMTIME_R)
89 // Get global lock (because gmtime uses a global buffer). FIXME
90 tim
= *(struct tm
*) gmtime (&t
);
91 // Release global lock. FIXME
96 #if defined(__JV_POSIX_THREADS__) && defined(HAVE_LOCALTIME_R)
97 localtime_r (&t
, &tim
);
99 // Get global lock (because localtime uses a global buffer). FIXME
100 tim
= *(struct tm
*) localtime (&t
);
101 // Release global lock. FIXME
105 elements(fields
)[SECOND
] = tim
.tm_sec
;
106 elements(fields
)[MINUTE
] = tim
.tm_min
;
107 elements(fields
)[HOUR_OF_DAY
] = tim
.tm_hour
;
108 elements(fields
)[AM_PM
] = tim
.tm_hour
< 12 ? AM
: PM
;
109 elements(fields
)[HOUR
] = tim
.tm_hour
% 12;
110 elements(fields
)[DATE
] = tim
.tm_mday
;
111 elements(fields
)[MONTH
] = tim
.tm_mon
;
112 elements(fields
)[YEAR
] = 1900 + tim
.tm_year
;
113 elements(fields
)[DAY_OF_WEEK
] = tim
.tm_wday
+ 1;
114 elements(fields
)[DAY_OF_WEEK_IN_MONTH
] = ((tim
.tm_mday
- 1) / 7) + 1;
115 elements(fields
)[DAY_OF_YEAR
] = tim
.tm_yday
+ 1;
116 elements(fields
)[WEEK_OF_MONTH
]
117 = (tim
.tm_mday
+ 6 + (5 - tim
.tm_wday
+ getFirstDayOfWeek()) % 7) / 7;
118 elements(fields
)[WEEK_OF_YEAR
]
119 = (tim
.tm_yday
+ 7 + (5 - tim
.tm_wday
+ getFirstDayOfWeek()) % 7) / 7;
120 elements(fields
)[ERA
] = AD
;
121 elements(fields
)[DST_OFFSET
] = tim
.tm_isdst
<= 0 ? 0 : 60*60*1000;
122 elements(fields
)[ZONE_OFFSET
] = getTimeZone()->getRawOffset();