FireBirdLib - Topfield TMS PVR TAP Programming Library
LocalTime2UTC.c
Go to the documentation of this file.
1#include "FBLib_time.h"
2
3dword LocalTime2UTC(dword LocalTime, short *Offset)
4{
6
7 bool DST;
8 short StdOffset, DSTOffset;
9 dword UTCTime, DSTStartUTC, DSTEndUTC;
10 dword ret;
11
13
14 if(!GetCurrentTimeZone(&StdOffset, &DST)) StdOffset = 60;
15
16 switch(DSTRule)
17 {
18 case DSTR_Undefined:
19 case DSTR_Firmware:
20 {
21 UTCTime = AddTime(LocalTime, -StdOffset);
22 if(DST) UTCTime = AddTime(UTCTime, -60);
23
24 TRACEEXIT();
25 return UTCTime;
26 }
27
28 case DSTR_Europe:
29 {
30 DST_GetTransitions_Europe(&DSTStartUTC, &DSTEndUTC, LocalTime);
31 break;
32 }
33
34 case DSTR_Manual:
35 {
36 DST_GetTransitions_Manual(&DSTStartUTC, &DSTEndUTC);
37 break;
38 }
39 }
40
41 //The local to UTC conversion has to be done in three steps.
42 //1.: the standard offset will be subtracted to get at least near to UTC
43 //2.: check against the transition times to determine if LocalTime is within the DST zone
44 //3.: if necessary, subtract the DST offset
45 UTCTime = AddTime(LocalTime, -StdOffset);
46 if(DSTStartUTC < DSTEndUTC)
47 {
48 //We are currently in standard time
49 DSTOffset = 0;
50
51 //Is UTCTime in DST?
52 if((UTCTime >= DSTStartUTC) && (UTCTime < DSTEndUTC)) DSTOffset = 60;
53 }
54 else
55 {
56 //We are currently in DST
57 DSTOffset = 60;
58
59 //Is UTCTime outside of the DST zone?
60 if((UTCTime >= DSTEndUTC) && (UTCTime < DSTStartUTC)) DSTOffset = 0;
61 }
62
63 if(Offset) *Offset = StdOffset + DSTOffset;
64 ret = AddTime(UTCTime, -DSTOffset);
65
66 TRACEEXIT();
67 return ret;
68}
void DST_GetDefaultDSTRule(void)
void DST_GetTransitions_Europe(dword *DSTStartUTC, dword *DSTEndUTC, dword StartDate)
void DST_GetTransitions_Manual(dword *DSTStartUTC, dword *DSTEndUTC)
tDSTRule DSTRule
Definition: DST_SetDSTRule.c:3
dword LocalTime2UTC(dword LocalTime, short *Offset)
Definition: LocalTime2UTC.c:3
dword AddTime(dword pvrDate, int addMinutes)
Definition: AddTime.c:3
#define TRACEEXIT()
Definition: libFireBird.h:1244
@ DSTR_Firmware
Definition: libFireBird.h:2697
@ DSTR_Europe
Definition: libFireBird.h:2698
@ DSTR_Manual
Definition: libFireBird.h:2699
@ DSTR_Undefined
Definition: libFireBird.h:2696
#define TRACEENTER()
Definition: libFireBird.h:1243
bool GetCurrentTimeZone(short *TZOffset, bool *DST)