File: fileclock.yo

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (55 lines) | stat: -rw-r--r-- 2,795 bytes parent folder | download | duplicates (2)
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
Time points obtained using ti(file_clock) differ from time points obtained
using the system clock: time points using tt(file_clock) are based on an epoch
that lies beyond the starting time point of the system clock (Jan 1, 00:00:00
1970) that is used by the system clock (Jan 1 00:00:00 2174). The two epochs
can be positioned on a time scale with the present somewhere in between:
    verb
(    <------|-----------------------|-----------------------|------->
      system_clock's -------->  present <--------    file_clock's
       epoch starts  positive            negative     epoch starts
                      count               count)

The tt(file_clock) has its own peculiarities: the static member tt(now) is
available, as are some non-static members: additions and subtractions of
durations and the member tt(time_since_epoch) can all be used, but the members 
tt(to_time_t) and tt(from_time_t) are not available.

Since tt(to_time_t) is not available for tt(file_clock) how can we show the
time or obtain the time's components of a tt(time_point<file_clock>) object?

Currently, there are two ways to accomplish that: compute the correction `by
hand' or use the static ti(file_clock::to_sys) function converting a
    hi(time_point<file_clock>)
tt(file_clock) time point to a tt(time_point) as used by tt(system_clock,
steady_clock,) and tt(high_resolution_clock).
    
Computing the difference between the epochs we find
6'437'663'999 seconds, which we can add to the obtained time since the
tt(file_clock's) epoch to obtain the time since the tt(system_clock's)
epoch. If tt(timePt) holds the duration since the tt(file_clock) epoch then
        verb(    6'437'663'999 + system_clock::to_time_t(
                        time_point<system_clock>{ nanoseconds(timePt) }))

    equals the number of seconds since the tt(system_clock's) epoch.

The potential drawback of this procedure is that, as tt(file_clock's)
name starts with underscores, the begin of its epoch might change. By using
the tt(now) members of both clocks this drawback is avoided:
        verb(    auto systemNow = system_clock::now().time_since_epoch();
    auto fileNow = file_clock::now().time_since_epoch();
    time_t diff = (systemNow - fileNow) / 1'000'000'000;

    time_t seconds = diff + system_clock::to_time_t(
                        time_point<system_clock>{ nanoseconds(timePt) });)

Although being able to compute the time-shifts yourself is attractive from
an understanding point of view, it's maybe also a bit (too) cumbersome for
daily practices. The static function tt(file_clock::to_sys) can be used to
convert tt(file_clock::time_points) to tt(system_clock:::time_points). The
tt(file_clock::to_sys) function is covered in section ref(FREEFS).

COMMENT( see examples/lastwritetime[2].cc)