blob: 30e533036c6a63e609ce3eecfe6fb680f06fbd7c [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2005 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_TIME_H
18#define ANDROID_TIME_H
19
20#include <stdint.h>
21#include <sys/types.h>
22#include <sys/time.h>
23#include <time.h>
24#include <utils/String8.h>
25#include <utils/String16.h>
26
27namespace android {
28
29/*
30 * This class is the core implementation of the android.util.Time java
31 * class. It doesn't implement some of the methods that are implemented
32 * in Java. They could be done here, but it's not expected that this class
33 * will be used. If that assumption is incorrect, feel free to update this
34 * file. The reason to do it here is to not mix the implementation of this
35 * class and the jni glue code.
36 */
37class Time
38{
39public:
40 struct tm t;
41
42 // this object doesn't own this string
43 const char *timezone;
44
45 enum {
46 SEC = 1,
47 MIN = 2,
48 HOUR = 3,
49 MDAY = 4,
50 MON = 5,
51 YEAR = 6,
52 WDAY = 7,
53 YDAY = 8
54 };
55
56 static int compare(Time& a, Time& b);
57
58 Time();
59
60 void switchTimezone(const char *timezone);
61 String8 format(const char *format) const;
62 void format2445(short* buf, bool hasTime) const;
63 String8 toString() const;
64 void setToNow();
65 int64_t toMillis(bool ignoreDst);
66 void set(int64_t millis);
67
68 inline void set(int sec, int min, int hour, int mday, int mon, int year,
69 int isdst)
70 {
71 this->t.tm_sec = sec;
72 this->t.tm_min = min;
73 this->t.tm_hour = hour;
74 this->t.tm_mday = mday;
75 this->t.tm_mon = mon;
76 this->t.tm_year = year;
77 this->t.tm_isdst = isdst;
78#ifdef HAVE_TM_GMTOFF
79 this->t.tm_gmtoff = 0;
80#endif
81 this->t.tm_wday = 0;
82 this->t.tm_yday = 0;
83 }
84};
85
86}; // namespace android
87
88#endif // ANDROID_TIME_H