File: format-ddiff.texi

package info (click to toggle)
dateutils 0.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,924 kB
  • sloc: ansic: 22,097; makefile: 1,666; yacc: 198; sh: 168; lex: 108
file content (100 lines) | stat: -rw-r--r-- 3,701 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
@section Format specs for durations

Unlike time or absolute instants, durations are reference-free, i.e. the
reference instant is not part of the duration.  As a result durations
cannot be named, i.e. there is no naming scheme that applies to all
durations and all references unambiguously.

Consequently, none of the format specifiers for date/times makes sense
for durations in the literal sense.  However, to aid intuitive usage we
reused format specifiers when they represent integral values and a valid
unit for duration, as follows:

Date specs:
@verbatim
  %c  Equivalent to %w
  %d  Duration in days
  %F  Equivalent to %dd with no resorting to bigger units
  %m  Duration in months
  %w  Duration in weeks
  %y  Equivalent to %Y
  %Y  Duration in years

  %db Duration in business days
  %dB Equivalent to %db
@end verbatim

Time specs:
@verbatim
  %H  Duration in hours
  %I  Equivalent to %H
  %M  Duration in minutes
  %S  Duration in seconds
  %T  Equivalent to %Ss without resorting to bigger units

  %rS Duration in real-life seconds, as in including leap seconds
  %rT Equivalent to %rSs without resorting to bigger units
@end verbatim

General specs:
@verbatim
  %n  A newline character
  %t  A tab character
  %%  A literal % character
@end verbatim

Modifiers:
@verbatim
  %r    Modifier to turn units into real units
  %0    Modifier to pad refined values with zeroes
  %SPC  Modifier to pad refined values with spaces
  b     Suffix, treat days as business days
@end verbatim


@section The refinement rule

Durations are somewhat ambiguous when it comes to representing them
through format specifiers.  Unlike format specifiers in point-in-time
representations duration specifiers can have an intra-line relationship.

So for instance a duration of 128 seconds might be presented through
@samp{%S} as @samp{128} but similarly through @samp{%M:%S} as
@samp{02:08} (read two minutes and 8 seconds).

There are several approaches to deal with this ambiguity.  The ddiff
tool will follow, what we call, the refinement rule.  That is,
regardless of the position of a format specifier, if it is a valid
/refinement/ of another specifier in the format string, then it
will only show the fractional value, i.e. the value in its natural range
with respect to the /refined/ specifier.

@verbatim
  %Y  possible refinements: %m, %w, %d
  %m  possible refinements: %w, %d
  %w  possible refinements: %d
  %d  possible refinements: %H, %M, %S
  %H  possible refinements: %M, %S
  %M  possible refinements: %S
@end verbatim

The refinement alternatives are listed in order of precedence and they
are mutually exclusive.  I.e. it is not possible to express a duration
in months and hours without having a @samp{%d} specifier as well.  On
the other hand in a chain of refinements inner elements are optional,
i.e. you can express a duration in weeks and hours because every day has
24 hours and hence there are 168 hours in a week.

In case of negative durations (the minuend is in the future relative to
the subtrahend) only the largest unit will carry the minus sign.

Using the refinement rule keeps the format string dead simple, there's
no need for operators or a full-blown language to distinguish the range
ambiguity, which then would have to be escaped because they could also
in theory be part of the literal characters of the format string,
resulting more often than not in command lines that are hard to craft
and even harder to understand later on (e.g. if used in shell scripts).

The refinement rule ingeniously covers the 99% case but, unlike other
approaches, there's no way to display two unrefined values in the
same format string, e.g. @samp{'%w weeks (which is %d days)'}.