summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/std/time/clock/gps/1.cc
blob: f6bfe49207d3ee1b768a7ad74a5c4543ab8e5e88 (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// { dg-options "-std=gnu++20" }
// { dg-do run { target c++20 } }

#include <chrono>
#include <testsuite_hooks.h>

void
test01()
{
  using namespace std::chrono;

  gps_seconds gps_epoch{0s};
  utc_seconds gps_as_utc{sys_days{1980y/January/Sunday[1]}.time_since_epoch() + 9s};

  VERIFY( clock_cast<utc_clock>(gps_epoch) == gps_as_utc );
  VERIFY( gps_epoch == clock_cast<gps_clock>(gps_as_utc) );

  tai_seconds tai_epoch{0s};
  VERIFY( clock_cast<tai_clock>(clock_cast<gps_clock>(tai_epoch)) == tai_epoch );
}

void
test02()
{
  using namespace std::chrono;

  sys_days d{2022y/November/12};
  VERIFY( clock_cast<system_clock>(clock_cast<gps_clock>(d)) == d );
  gps_seconds t(1234567s);
  VERIFY( clock_cast<gps_clock>(clock_cast<system_clock>(t)) == t );
  VERIFY( clock_cast<gps_clock>(clock_cast<utc_clock>(t)) == t );
}

void
test03()
{
  using namespace std::chrono;

  gps_time<gps_clock::duration> gps1 = gps_clock::now();
  utc_time<utc_clock::duration> utc = utc_clock::now();
  gps_time<gps_clock::duration> gps2 = gps_clock::now();

  auto delta = gps2 - gps1;
  VERIFY( (utc - clock_cast<utc_clock>(gps1)) <= delta );
  VERIFY( (clock_cast<utc_clock>(gps2) - utc) <= delta );

  gps_seconds s = time_point_cast<seconds>(gps1);
  VERIFY( gps1 - s < 1s );
}

int main()
{
  test01();
  test02();
  test03();
}