static time_type create_time(time_converter converter)
{
timeval tv;
gettimeofday(&tv,
0
);
/
/
gettimeofday does
not
support TZ adjust on Linux.
std::time_t t
=
tv.tv_sec;
boost::uint32_t sub_sec
=
tv.tv_usec;
winapi::file_time ft;
winapi::get_system_time_as_file_time(ft);
uint64_t micros
=
winapi::file_time_to_microseconds(ft);
/
/
it will
not
wrap, since ft
is
the current time
/
/
and
cannot be before
1970
-
Jan
-
01
std::time_t t
=
static_cast(micros
/
1000000UL
);
/
/
seconds since epoch
/
/
microseconds
-
-
static casts suppress warnings
mars_boost::uint32_t sub_sec
=
static_cast(micros
%
1000000UL
);
std::tm curr;
std::tm
*
curr_ptr
=
converter(&t, &curr);
date_type d(static_cast< typename date_type::year_type::value_type >(curr_ptr
-
>tm_year
+
1900
),
static_cast< typename date_type::month_type::value_type >(curr_ptr
-
>tm_mon
+
1
),
static_cast< typename date_type::day_type::value_type >(curr_ptr
-
>tm_mday));
/
/
The following line will adjust the fractional second tick
in
terms
/
/
of the current time system. For example,
if
the time system
/
/
doesn't support fractional seconds then res_adjust returns
0
/
/
and
all
the fractional seconds
return
0.
int
adjust
=
static_cast<
int
>(resolution_traits_type::res_adjust()
/
1000000
);
time_duration_type td(static_cast< typename time_duration_type::hour_type >(curr_ptr
-
>tm_hour),
static_cast< typename time_duration_type::min_type >(curr_ptr
-
>tm_min),
static_cast< typename time_duration_type::sec_type >(curr_ptr
-
>tm_sec),
sub_sec
*
adjust);
return
time_type(d,td);
}