From a15cf8adb15821a895718a85aafc3c8f06d9e6f1 Mon Sep 17 00:00:00 2001 From: Fritz Elfert Date: Fri, 15 Feb 2002 08:50:04 +0000 Subject: - Fixed psitime again. Waaahh, these guys at symbian change filetimes when switching DST/Non-DST. --- include/plp_inttypes.h | 35 +++++++++++++++++++++++++++++++++++ lib/psitime.cc | 13 ++++++++++--- lib/psitime.h | 2 +- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 include/plp_inttypes.h diff --git a/include/plp_inttypes.h b/include/plp_inttypes.h new file mode 100644 index 0000000..0c92d80 --- /dev/null +++ b/include/plp_inttypes.h @@ -0,0 +1,35 @@ +#ifndef _INTTYPES_H_ +#define _INTTYPES_H_ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#ifdef HAVE_STDINT_H +#include +#endif + +#ifdef HAVE_SYS_INT_TYPES_H +#include +#endif + +#ifndef GNU_INTTYPES +#ifdef ISO_INTTYPES +typedef uint8_t u_int8_t; +typedef uint16_t u_int16_t; +typedef uint32_t u_int32_t; +typedef uint64_t u_int64_t; +typedef int64_t s_int64_t; +#else +/* Last resort, declare ourselves */ +typedef unsigned char u_int8_t; +typedef unsigned short u_int16_t; +typedef unsigned int u_int32_t; +typedef unsigned long long u_int64_t; +typedef signed long long s_int64_t; +#endif // ISO_INTTYPES +#endif // GNU_INTTYPES + +#endif // _INTTYPES_H_ diff --git a/lib/psitime.cc b/lib/psitime.cc index e776ab9..298e494 100644 --- a/lib/psitime.cc +++ b/lib/psitime.cc @@ -22,6 +22,7 @@ */ #include "psitime.h" #include +#include PsiTime::PsiTime(void) { ptzValid = false; @@ -168,12 +169,12 @@ ostream &operator<<(ostream &s, const PsiTime &t) { static unsigned long long evalOffset(psi_timezone ptz, time_t time, bool valid) { - u_int64_t offset = 0; + s_int64_t offset = 0; if (valid) { offset = ptz.utc_offset; if (!(ptz.dst_zones & 0x40000000) || (ptz.dst_zones & ptz.home_zone)) - offset += 3600; + offset -= 3600; } else { /** * Fallback. If no Psion zone given, use @@ -199,6 +200,12 @@ evalOffset(psi_timezone ptz, time_t time, bool valid) { offset += 3600; } } + // Substract out local timezone, it gets added + // later + time_t now = ::time(0); + struct tm *now_tm = localtime(&now); + offset -= timezone; + offset *= 1000000; return offset; } @@ -216,7 +223,7 @@ void PsiTime::psi2unix(void) { } void PsiTime::unix2psi(void) { - u_int64_t micro = utv.tv_sec * 1000000 + utv.tv_usec; + u_int64_t micro = (u_int64_t)utv.tv_sec * 1000000ULL + utv.tv_usec; /* Add Psion's idea of UTC offset */ micro += evalOffset(ptz, utv.tv_sec, ptzValid); diff --git a/lib/psitime.h b/lib/psitime.h index be9122c..587faaf 100644 --- a/lib/psitime.h +++ b/lib/psitime.h @@ -105,7 +105,7 @@ typedef struct psi_timezone_t { s.flags(old); return s; } - unsigned long utc_offset; + signed long utc_offset; unsigned long dst_zones; unsigned long home_zone; } psi_timezone; -- cgit v1.2.3