Implement tzset(), gmtime(), localtime() and mktime() on top of ICU
* no longer keep a separate time-backend, since the implementation needs to access (data of) the locale backend anyway * moved more stuff from localtime_fading_out.c to localtime.cpp * added respective tests to locale_test * added two more tests copied from glibc, test_time.c and tst-mktime.c git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38162 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "ICUMessagesData.h"
|
||||
#include "ICUMonetaryData.h"
|
||||
#include "ICUNumericData.h"
|
||||
#include "ICUTimeConversion.h"
|
||||
#include "ICUTimeData.h"
|
||||
|
||||
|
||||
@@ -44,6 +45,13 @@ public:
|
||||
virtual status_t Strxfrm(char* out, const char* in, size_t size,
|
||||
size_t& outSize);
|
||||
|
||||
virtual status_t TZSet(const char* timeZoneID);
|
||||
virtual status_t Localtime(const time_t* inTime,
|
||||
struct tm* tmOut);
|
||||
virtual status_t Gmtime(const time_t* inTime, struct tm* tmOut);
|
||||
|
||||
virtual status_t Mktime(struct tm* inOutTm, time_t& timeOut);
|
||||
|
||||
private:
|
||||
const char* _QueryLocale(int category);
|
||||
const char* _SetPosixLocale(int category);
|
||||
@@ -62,6 +70,7 @@ private:
|
||||
ICUMonetaryData fMonetaryData;
|
||||
ICUNumericData fNumericData;
|
||||
ICUTimeData fTimeData;
|
||||
ICUTimeConversion fTimeConversion;
|
||||
|
||||
// static posix langinfo data
|
||||
const char** fPosixLanginfo;
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2010, Oliver Tappe, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _ICU_TIME_CONVERSION_H
|
||||
#define _ICU_TIME_CONVERSION_H
|
||||
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "ICUTimeData.h"
|
||||
#include "LocaleBackend.h"
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class ICUTimeConversion {
|
||||
public:
|
||||
ICUTimeConversion(const ICUTimeData& timeData);
|
||||
virtual ~ICUTimeConversion();
|
||||
|
||||
virtual void Initialize(
|
||||
TimeConversionDataBridge* dataBridge);
|
||||
|
||||
status_t TZSet(const char* timeZoneID);
|
||||
|
||||
status_t Localtime(const time_t* inTime,
|
||||
struct tm* tmOut);
|
||||
status_t Gmtime(const time_t* inTime, struct tm* tmOut);
|
||||
|
||||
status_t Mktime(struct tm* inOutTm, time_t& timeOut);
|
||||
|
||||
private:
|
||||
status_t _FillTmValues(const TimeZone* icuTimeZone,
|
||||
const time_t* inTime, struct tm* tmOut);
|
||||
|
||||
const ICUTimeData& fTimeData;
|
||||
|
||||
TimeConversionDataBridge* fDataBridge;
|
||||
|
||||
char fTimeZoneID[64];
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
#endif // _ICU_TIME_BACKEND_H
|
||||
@@ -21,6 +21,7 @@ class ICUTimeData : public ICUCategoryData {
|
||||
typedef ICUCategoryData inherited;
|
||||
public:
|
||||
ICUTimeData(struct lc_time_t& lcTimeInfo);
|
||||
~ICUTimeData();
|
||||
|
||||
void Initialize(LocaleTimeDataBridge* dataBridge);
|
||||
|
||||
@@ -30,6 +31,8 @@ public:
|
||||
|
||||
const char* GetLanginfo(int index);
|
||||
|
||||
const Locale& ICULocale() const;
|
||||
|
||||
private:
|
||||
status_t _SetLCTimeEntries(const UnicodeString* strings,
|
||||
char* destination, int entrySize,
|
||||
@@ -52,7 +55,8 @@ private:
|
||||
char fAmPmFormat[32];
|
||||
|
||||
struct lc_time_t& fLCTimeInfo;
|
||||
const struct lc_time_t* fPosixLCTimeInfo;
|
||||
|
||||
LocaleTimeDataBridge* fDataBridge;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <wctype.h>
|
||||
|
||||
|
||||
@@ -64,12 +65,22 @@ struct LocaleTimeDataBridge {
|
||||
};
|
||||
|
||||
|
||||
struct TimeConversionDataBridge {
|
||||
int* addrOfDaylight;
|
||||
long* addrOfTimezone;
|
||||
char** addrOfTZName;
|
||||
|
||||
TimeConversionDataBridge();
|
||||
};
|
||||
|
||||
|
||||
struct LocaleDataBridge {
|
||||
LocaleCtypeDataBridge ctypeDataBridge;
|
||||
LocaleMessagesDataBridge messagesDataBridge;
|
||||
LocaleMonetaryDataBridge monetaryDataBridge;
|
||||
LocaleNumericDataBridge numericDataBridge;
|
||||
LocaleTimeDataBridge timeDataBridge;
|
||||
TimeConversionDataBridge timeConversionDataBridge;
|
||||
const char** posixLanginfo;
|
||||
|
||||
LocaleDataBridge();
|
||||
@@ -96,6 +107,13 @@ public:
|
||||
virtual status_t Strxfrm(char* out, const char* in, size_t size,
|
||||
size_t& outSize) = 0;
|
||||
|
||||
virtual status_t TZSet(const char* timeZoneID) = 0;
|
||||
virtual status_t Localtime(const time_t* inTime,
|
||||
struct tm* tmOut) = 0;
|
||||
virtual status_t Gmtime(const time_t* inTime,
|
||||
struct tm* tmOut) = 0;
|
||||
virtual status_t Mktime(struct tm* inOutTm, time_t& timeOut) = 0;
|
||||
|
||||
virtual void Initialize(LocaleDataBridge* dataBridge) = 0;
|
||||
|
||||
static status_t LoadBackend();
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010, Oliver Tappe, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _ICU_TIME_BACKEND_H
|
||||
#define _ICU_TIME_BACKEND_H
|
||||
|
||||
|
||||
#include <TimeBackend.h>
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class ICUTimeBackend : public TimeBackend {
|
||||
public:
|
||||
ICUTimeBackend();
|
||||
virtual ~ICUTimeBackend();
|
||||
|
||||
virtual const status_t TZSet();
|
||||
|
||||
virtual void Initialize(TimeDataBridge* dataBridge);
|
||||
|
||||
private:
|
||||
TimeDataBridge fDataBridge;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
#endif // _ICU_TIME_BACKEND_H
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010, Oliver Tappe, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _TIME_BACKEND_H
|
||||
#define _TIME_BACKEND_H
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
struct TimeDataBridge {
|
||||
int* addrOfDaylight;
|
||||
long* addrOfTimezone;
|
||||
char** addrOfTZName;
|
||||
|
||||
TimeDataBridge();
|
||||
};
|
||||
|
||||
|
||||
class TimeBackend {
|
||||
public:
|
||||
TimeBackend();
|
||||
virtual ~TimeBackend();
|
||||
|
||||
virtual const status_t TZSet() = 0;
|
||||
|
||||
virtual void Initialize(TimeDataBridge* dataBridge) = 0;
|
||||
|
||||
static status_t LoadBackend();
|
||||
};
|
||||
|
||||
|
||||
extern TimeBackend* gTimeBackend;
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
#endif // _TIME_BACKEND_H
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010, Oliver Tappe, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _LOCALTIME_H
|
||||
#define _LOCALTIME_H
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
static const char* skPosixTimeZoneInfoFile = "libroot_timezone_info";
|
||||
static const int skTimeZoneInfoNameMax = 32;
|
||||
|
||||
// holds persistent info set by Time preflet
|
||||
struct time_zone_info {
|
||||
char short_std_name[skTimeZoneInfoNameMax];
|
||||
char short_dst_name[skTimeZoneInfoNameMax];
|
||||
uint32 offset_from_gmt;
|
||||
bool uses_daylight_saving;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
#endif // _LOCALTIME_H
|
||||
Reference in New Issue
Block a user