ReactOS 0.4.16-dev-927-g467dec4
loctotime.cpp File Reference
Include dependency graph for loctotime.cpp:

Go to the source code of this file.

Functions

template<typename TimeType >
static TimeType __cdecl common_loctotime_t (int yr, int const mo, int const dy, int const hr, int const mn, int const sc, int const dstflag) throw ()
 
__time32_t __cdecl __loctotime32_t (int const yr, int const mo, int const dy, int const hr, int const mn, int const sc, int const dstflag)
 
__time64_t __cdecl __loctotime64_t (int const yr, int const mo, int const dy, int const hr, int const mn, int const sc, int const dstflag)
 

Function Documentation

◆ __loctotime32_t()

__time32_t __cdecl __loctotime32_t ( int const  yr,
int const  mo,
int const  dy,
int const  hr,
int const  mn,
int const  sc,
int const  dstflag 
)

Definition at line 93 of file loctotime.cpp.

102{
103 return common_loctotime_t<__time32_t>(yr, mo, dy, hr, mn, sc, dstflag);
104}
GLint dy
Definition: linetemp.h:97
HRESULT hr
Definition: shlfolder.c:183

Referenced by convert_system_time_to_time_t().

◆ __loctotime64_t()

__time64_t __cdecl __loctotime64_t ( int const  yr,
int const  mo,
int const  dy,
int const  hr,
int const  mn,
int const  sc,
int const  dstflag 
)

Definition at line 106 of file loctotime.cpp.

115{
116 return common_loctotime_t<__time64_t>(yr, mo, dy, hr, mn, sc, dstflag);
117}

Referenced by convert_system_time_to_time_t().

◆ common_loctotime_t()

template<typename TimeType >
static TimeType __cdecl common_loctotime_t ( int  yr,
int const  mo,
int const  dy,
int const  hr,
int const  mn,
int const  sc,
int const  dstflag 
)
throw (
)
static

Definition at line 17 of file loctotime.cpp.

26{
27 typedef __crt_time_time_t_traits<TimeType> time_traits;
28
29 static TimeType const invalid_time = static_cast<TimeType>(-1);
30
31 // Adjust the absolute year to be an offset from the year 1900:
32 yr -= 1900;
33
34 _VALIDATE_RETURN_NOEXC(yr >= _BASE_YEAR && yr <= time_traits::max_year, EINVAL, invalid_time)
35 _VALIDATE_RETURN_NOEXC(mo >= 1 && mo <= 12, EINVAL, invalid_time)
36 _VALIDATE_RETURN_NOEXC(__crt_time_is_day_valid(yr, mo - 1, dy), EINVAL, invalid_time)
37 _VALIDATE_RETURN_NOEXC(hr >= 0 && hr <= 23, EINVAL, invalid_time)
38 _VALIDATE_RETURN_NOEXC(mn >= 0 && mn <= 59, EINVAL, invalid_time)
39 _VALIDATE_RETURN_NOEXC(sc >= 0 && sc <= 59, EINVAL, invalid_time)
40
41 // Compute the number of elapsed days in the current year:
42 int elapsed_days_this_year = dy + _days[mo - 1];
43 if (__crt_time_is_leap_year(yr) && mo > 2)
44 ++elapsed_days_this_year;
45
46 TimeType const elapsed_years = static_cast<TimeType>(yr) - _BASE_YEAR;
47 TimeType const elapsed_leap_years = static_cast<TimeType>(__crt_time_elapsed_leap_years(yr));
48
49 // The number of elapsed days is the number of days in each completed year
50 // since the epoch, plus one day per leap year, plus the number of days
51 // elapsed so far this year:
52 TimeType const elapsed_days =
53 elapsed_years * 365 +
54 elapsed_leap_years +
55 elapsed_days_this_year;
56
57 TimeType const elapsed_hours = elapsed_days * 24 + hr;
58 TimeType const elapsed_minutes = elapsed_hours * 60 + mn;
59 TimeType const elapsed_seconds = elapsed_minutes * 60 + sc;
60
61 // Account for the time zone:
62 __tzset();
63
64 int daylight = 0;
65 long dstbias = 0;
66 long timezone = 0;
68 _ERRCHECK(_get_dstbias (&dstbias ));
70
71 TimeType const timezone_adjusted_seconds = elapsed_seconds + timezone;
72
73 // Determine whether we are in Daylight Savings Time and adjust:
74 TimeType const dst_adjusted_seconds = timezone_adjusted_seconds + dstbias;
75
76 if (dstflag == 1)
77 return dst_adjusted_seconds;
78
79 tm tm_value;
80 tm_value.tm_yday = elapsed_days_this_year;
81 tm_value.tm_year = yr;
82 tm_value.tm_mon = mo - 1;
83 tm_value.tm_hour = hr;
84 tm_value.tm_min = mn;
85 tm_value.tm_sec = sc;
86 if (dstflag == -1 && daylight != 0 && _isindst(&tm_value))
87 return dst_adjusted_seconds;
88
89 // Otherwise, we are not in Daylight Savings Time:
90 return timezone_adjusted_seconds;
91}
#define EINVAL
Definition: acclib.h:90
#define _ERRCHECK(e)
void __cdecl __tzset()
Definition: tzset.cpp:392
#define _BASE_YEAR
int __cdecl _isindst(_In_ tm *_Time)
bool __cdecl __crt_time_is_leap_year(TimeType const yr)
TimeType __cdecl __crt_time_elapsed_leap_years(TimeType const yr)
int const _days[]
Definition: days.cpp:14
bool __cdecl __crt_time_is_day_valid(int const yr, int const mo, int const dy)
#define _VALIDATE_RETURN_NOEXC(expr, errorcode, retexpr)
_CRTIMP errno_t __cdecl _get_daylight(_Out_ int *_Daylight)
_CRTIMP errno_t __cdecl _get_dstbias(_Out_ long *_Daylight_savings_bias)
_CRTIMP int daylight
_CRTIMP errno_t __cdecl _get_timezone(_Out_ long *_Timezone)
Definition: fake.h:14
Definition: time.h:68
int tm_mon
Definition: time.h:73
int tm_year
Definition: time.h:74
int tm_hour
Definition: time.h:71
int tm_sec
Definition: time.h:69
int tm_yday
Definition: time.h:76
int tm_min
Definition: time.h:70