File: TestConvert.cxx

package info (click to toggle)
mpd 0.24.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,736 kB
  • sloc: cpp: 75,014; python: 1,408; xml: 628; perl: 469; java: 289; sh: 286; ansic: 235; makefile: 105
file content (36 lines) | stat: -rw-r--r-- 715 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// SPDX-License-Identifier: BSD-2-Clause
// author: Max Kellermann <max.kellermann@gmail.com>

#include "time/Convert.hxx"

#include <gtest/gtest.h>

static constexpr time_t times[] = {
	1234567890,
	1580566807,
	1585750807,
	1590934807,
};

TEST(Time, LocalTime)
{
	/* convert back and forth using local time zone */

	for (const auto t : times) {
		auto tp = std::chrono::system_clock::from_time_t(t);
		auto tm = LocalTime(tp);
		EXPECT_EQ(MakeTime(tm), tp);
	}
}

TEST(Time, GmTime)
{
	/* convert back and forth using UTC */

	for (const auto t : times) {
		auto tp = std::chrono::system_clock::from_time_t(t);
		auto tm = GmTime(tp);
		EXPECT_EQ(std::chrono::system_clock::to_time_t(TimeGm(tm)),
			  t);
	}
}