Added support for retrieving the timezone at any time, not just now.
Fixed the Javascript Date getTimezoneOffset() result. git-svn-id: http://voip.null.ro/svn/yate@6396 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
2eae0b863f
commit
1fd6d25f05
|
@ -975,11 +975,11 @@ uint64_t Time::toEpoch(const char* buf, unsigned int len, int frac)
|
|||
return sec * 1000000 + delta;
|
||||
}
|
||||
|
||||
int Time::timeZone()
|
||||
int Time::timeZone(u_int32_t when)
|
||||
{
|
||||
#ifdef _WINDOWS
|
||||
struct tm t;
|
||||
time_t time = (time_t)secNow();
|
||||
time_t time = (time_t)when;
|
||||
_localtime_s(&t,&time);
|
||||
if (t.tm_isdst)
|
||||
return -(_timezone + _dstbias);
|
||||
|
@ -987,7 +987,7 @@ int Time::timeZone()
|
|||
#else
|
||||
#ifdef HAVE_GMTOFF
|
||||
struct tm t;
|
||||
time_t time = (time_t)secNow();
|
||||
time_t time = (time_t)when;
|
||||
if (localtime_r(&time,&t))
|
||||
return t.tm_gmtoff;
|
||||
#endif
|
||||
|
|
|
@ -88,7 +88,7 @@ public:
|
|||
protected:
|
||||
inline JsDate(Mutex* mtx, u_int64_t msecs, bool local = false)
|
||||
: JsObject("Date",mtx),
|
||||
m_time((unsigned int)(msecs / 1000)), m_msec((unsigned int)(msecs % 1000)), m_offs(Time::timeZone())
|
||||
m_time((unsigned int)(msecs / 1000)), m_msec((unsigned int)(msecs % 1000)), m_offs(Time::timeZone(m_time))
|
||||
{ if (local) m_time -= m_offs; }
|
||||
inline JsDate(Mutex* mtx, const char* name, unsigned int time, unsigned int msec, unsigned int offs)
|
||||
: JsObject(mtx,name),
|
||||
|
|
|
@ -3928,9 +3928,10 @@ public:
|
|||
|
||||
/**
|
||||
* Retrieve the difference between local time and UTC in seconds east of UTC
|
||||
* @param when UNIX time for which to compute timezone, affects daylight saving
|
||||
* @return Difference between local time and UTC in seconds
|
||||
*/
|
||||
static int timeZone();
|
||||
static int timeZone(u_int32_t when = secNow());
|
||||
|
||||
private:
|
||||
u_int64_t m_time;
|
||||
|
|
Loading…
Reference in New Issue