@@ -130,24 +130,22 @@ int64_t update_from_seconds(int64_t total_seconds, struct tm *tm) {
130130 if (years > INT_MAX || years < INT_MIN)
131131 return time_utils::out_of_range ();
132132
133+ char timezone[128 ];
134+
133135 FILE *fp;
134136 fp = fopen (" /etc/timezone" , " rb" );
135137 if (fp == NULL ) {
138+ // TODO: implement getting timezone from `TZ` environment variable and
139+ // storing the value in `timezone`
140+ } else if (fgets (timezone, sizeof (timezone), fp) == NULL )
136141 return time_utils::out_of_range ();
137- }
138-
139- char timezone[128 ];
140- if (fgets (timezone, sizeof (timezone), fp) == NULL ) {
141- return time_utils::out_of_range ();
142- }
143142
144143 int offset;
145- if (internal::same_string (timezone, " UTC" ) == 0 ) {
144+ // TODO: Add more timezones
145+ if (internal::same_string (timezone, " UTC" ) == 0 )
146146 offset = 0 ;
147- }
148- if (internal::same_string (timezone, " Europe/Berlin" ) == 0 ) {
147+ if (internal::same_string (timezone, " Europe/Berlin" ) == 0 )
149148 offset = 2 ;
150- }
151149
152150 // All the data (years, month and remaining days) was calculated from
153151 // March, 2000. Thus adjust the data to be from January, 1900.
@@ -167,9 +165,11 @@ int64_t update_from_seconds(int64_t total_seconds, struct tm *tm) {
167165
168166 if (offset == 0 ) {
169167 tm->tm_isdst = 0 ;
170- } else {
168+ } else if (offset > 0 ) {
171169 tm->tm_isdst = 1 ;
172170 tm->tm_hour += offset;
171+ } else {
172+ tm->tm_isdst = -1 ;
173173 }
174174
175175 fclose (fp);
0 commit comments