• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <sys/cdefs.h>
18 #include <features.h>
19 #include <gtest/gtest.h>
20 
21 #include <time.h>
22 
23 #ifdef __BIONIC__ // mktime_tz is a bionic extension.
24 #include <libc/private/bionic_time.h>
TEST(time,mktime_tz)25 TEST(time, mktime_tz) {
26   struct tm epoch;
27   memset(&epoch, 0, sizeof(tm));
28   epoch.tm_year = 1970 - 1900;
29   epoch.tm_mon = 1;
30   epoch.tm_mday = 1;
31 
32   // Alphabetically first. Coincidentally equivalent to UTC.
33   ASSERT_EQ(2678400, mktime_tz(&epoch, "Africa/Abidjan"));
34 
35   // Alphabetically last. Coincidentally equivalent to UTC.
36   ASSERT_EQ(2678400, mktime_tz(&epoch, "Zulu"));
37 
38   // Somewhere in the middle, not UTC.
39   ASSERT_EQ(2707200, mktime_tz(&epoch, "America/Los_Angeles"));
40 
41   // Missing. Falls back to UTC.
42   ASSERT_EQ(2678400, mktime_tz(&epoch, "PST"));
43 }
44 #endif
45