]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/date_time/test/posix_time/testfiletime_functions.cpp
1 /* Copyright (c) 2002,2003, 2004 CrystalClear Software, Inc.
2 * Use, modification and distribution is subject to the
3 * Boost Software License, Version 1.0. (See accompanying
4 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
5 * Author: Jeff Garland, Bart Garst
8 #include "boost/date_time/posix_time/posix_time.hpp"
9 #include "../testfrmwk.hpp"
10 #include "boost/date_time/filetime_functions.hpp"
13 #if defined(BOOST_HAS_FTIME)
19 #if defined(BOOST_HAS_FTIME) // skip tests if no FILETIME
21 using namespace boost::posix_time
;
23 // adjustor is used to truncate ptime's fractional seconds for
24 // comparison with SYSTEMTIME's milliseconds
25 const time_duration::tick_type adjustor
= time_duration::ticks_per_second() / 1000;
27 for(int i
= 0; i
< 5; ++i
){
32 SystemTimeToFileTime(&st
,&ft
);
34 ptime pt
= from_ftime
<ptime
>(ft
);
36 check_equal("ptime year matches systemtime year",
37 st
.wYear
, pt
.date().year());
38 check_equal("ptime month matches systemtime month",
39 st
.wMonth
, pt
.date().month());
40 check_equal("ptime day matches systemtime day",
41 st
.wDay
, pt
.date().day());
42 check_equal("ptime hour matches systemtime hour",
43 st
.wHour
, pt
.time_of_day().hours());
44 check_equal("ptime minute matches systemtime minute",
45 st
.wMinute
, pt
.time_of_day().minutes());
46 check_equal("ptime second matches systemtime second",
47 st
.wSecond
, pt
.time_of_day().seconds());
48 check_equal("truncated ptime fractional second matches systemtime millisecond",
49 st
.wMilliseconds
, (pt
.time_of_day().fractional_seconds() / adjustor
));
51 // burn up a little time
52 for (int j
=0; j
<100000; j
++)
60 // check that time_from_ftime works for pre-1970-Jan-01 dates, too
61 // zero FILETIME should represent 1601-Jan-01 00:00:00.000
62 FILETIME big_bang_by_ms
;
63 big_bang_by_ms
.dwLowDateTime
= big_bang_by_ms
.dwHighDateTime
= 0;
64 ptime pt
= from_ftime
<ptime
>(big_bang_by_ms
);
66 check_equal("big bang ptime year matches 1601",
67 1601, pt
.date().year());
68 check_equal("big bang ptime month matches Jan",
69 1, pt
.date().month());
70 check_equal("big bang ptime day matches 1",
72 check_equal("big bang ptime hour matches 0",
73 0, pt
.time_of_day().hours());
74 check_equal("big bang ptime minute matches 0",
75 0, pt
.time_of_day().minutes());
76 check_equal("big bang ptime second matches 0",
77 0, pt
.time_of_day().seconds());
78 check_equal("big bang truncated ptime fractional second matches 0",
79 0, (pt
.time_of_day().fractional_seconds() / adjustor
));
82 #else // BOOST_HAS_FTIME
83 // we don't want a forced failure here, not a shortcoming
84 check("FILETIME not available for this compiler/platform", true);
85 #endif // BOOST_HAS_FTIME
87 return printTestStats();