Home | History | Annotate | Download | only in jni
      1 /*
      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 <time.h>
     21 #include <cutils/tztime.h>
     22 #include <stdint.h>
     23 #include <sys/types.h>
     24 #include <sys/time.h>
     25 #include <utils/String8.h>
     26 #include <utils/String16.h>
     27 
     28 namespace android {
     29 
     30 /*
     31  * This class is the core implementation of the android.util.Time java
     32  * class.  It doesn't implement some of the methods that are implemented
     33  * in Java.  They could be done here, but it's not expected that this class
     34  * will be used.  If that assumption is incorrect, feel free to update this
     35  * file.  The reason to do it here is to not mix the implementation of this
     36  * class and the jni glue code.
     37  */
     38 class Time
     39 {
     40 public:
     41     struct tm t;
     42 
     43     // this object doesn't own this string
     44     const char *timezone;
     45 
     46     enum {
     47         SEC = 1,
     48         MIN = 2,
     49         HOUR = 3,
     50         MDAY = 4,
     51         MON = 5,
     52         YEAR = 6,
     53         WDAY = 7,
     54         YDAY = 8
     55     };
     56 
     57     static int compare(Time& a, Time& b);
     58 
     59     Time();
     60 
     61     void switchTimezone(const char *timezone);
     62     String8 format(const char *format, const struct strftime_locale *locale) const;
     63     void format2445(short* buf, bool hasTime) const;
     64     String8 toString() const;
     65     void setToNow();
     66     int64_t toMillis(bool ignoreDst);
     67     void set(int64_t millis);
     68 
     69     inline void set(int sec, int min, int hour, int mday, int mon, int year,
     70             int isdst)
     71     {
     72         this->t.tm_sec = sec;
     73         this->t.tm_min = min;
     74         this->t.tm_hour = hour;
     75         this->t.tm_mday = mday;
     76         this->t.tm_mon = mon;
     77         this->t.tm_year = year;
     78         this->t.tm_isdst = isdst;
     79 #ifdef HAVE_TM_GMTOFF
     80         this->t.tm_gmtoff = 0;
     81 #endif
     82         this->t.tm_wday = 0;
     83         this->t.tm_yday = 0;
     84     }
     85 };
     86 
     87 }; // namespace android
     88 
     89 #endif // ANDROID_TIME_H
     90