"Fossies" - the Fresh Open Source Software Archive

Member "dateutils-0.4.6/info/format-ddiff.th2m" (19 Mar 2019, 3537 Bytes) of package /linux/privat/dateutils-0.4.6.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "format-ddiff.th2m": 0.4.2_vs_0.4.3.

    1 [Format specs for durations]
    2 
    3 Unlike time or absolute instants, durations are reference-free, i.e. the
    4 reference instant is not part of the duration.  As a result durations
    5 cannot be named, i.e. there is no naming scheme that applies to all
    6 durations and all references unambiguously.
    7 
    8 Consequently, none of the format specifiers for date/times makes sense
    9 for durations in the literal sense.  However, to aid intuitive usage we
   10 reused format specifiers when they represent integral values and a valid
   11 unit for duration, as follows:
   12 
   13 Date specs:
   14   %c  Equivalent to %w
   15   %d  Duration in days
   16   %F  Equivalent to %dd with no resorting to bigger units
   17   %m  Duration in months
   18   %w  Duration in weeks
   19   %y  Equivalent to %Y
   20   %Y  Duration in years
   21 
   22   %db Duration in business days
   23   %dB Equivalent to %db
   24 
   25 Time specs:
   26   %H  Duration in hours
   27   %I  Equivalent to %H
   28   %M  Duration in minutes
   29   %S  Duration in seconds
   30   %T  Equivalent to %Ss without resorting to bigger units
   31 
   32   %rS Duration in real-life seconds, as in including leap seconds
   33   %rT Equivalent to %rSs without resorting to bigger units
   34 
   35 General specs:
   36   %n  A newline character
   37   %t  A tab character
   38   %%  A literal % character
   39 
   40 Modifiers:
   41   %r    Modifier to turn units into real units
   42   %0    Modifier to pad refined values with zeroes
   43   %SPC  Modifier to pad refined values with spaces
   44   b     Suffix, treat days as business days
   45 
   46 
   47 [The refinement rule]
   48 
   49 Durations are somewhat ambiguous when it comes to representing them
   50 through format specifiers.  Unlike format specifiers in point-in-time
   51 representations duration specifiers can have an intra-line relationship.
   52 
   53 So for instance a duration of 128 seconds might be presented through
   54 "%S" as "128" but similarly through "%M:%S" as
   55 "02:08" (read two minutes and 8 seconds).
   56 
   57 There are several approaches to deal with this ambiguity.  The ddiff
   58 tool will follow, what we call, the refinement rule.  That is,
   59 regardless of the position of a format specifier, if it is a valid
   60 /refinement/ of another specifier in the format string, then it
   61 will only show the fractional value, i.e. the value in its natural range
   62 with respect to the /refined/ specifier.
   63 
   64   %Y  possible refinements: %m, %w, %d
   65   %m  possible refinements: %w, %d
   66   %w  possible refinements: %d
   67   %d  possible refinements: %H, %M, %S
   68   %H  possible refinements: %M, %S
   69   %M  possible refinements: %S
   70 
   71 The refinement alternatives are listed in order of precedence and they
   72 are mutually exclusive.  I.e. it is not possible to express a duration
   73 in months and hours without having a "%d" specifier as well.  On
   74 the other hand in a chain of refinements inner elements are optional,
   75 i.e. you can express a duration in weeks and hours because every day has
   76 24 hours and hence there are 168 hours in a week.
   77 
   78 In case of negative durations (the minuend is in the future relative to
   79 the subtrahend) only the largest unit will carry the minus sign.
   80 
   81 Using the refinement rule keeps the format string dead simple, there's
   82 no need for operators or a full-blown language to distinguish the range
   83 ambiguity, which then would have to be escaped because they could also
   84 in theory be part of the literal characters of the format string,
   85 resulting more often than not in command lines that are hard to craft
   86 and even harder to understand later on (e.g. if used in shell scripts).
   87 
   88 The refinement rule ingeniously covers the 99% case but, unlike other
   89 approaches, there's no way to display two unrefined values in the
   90 same format string, e.g. "'%w weeks (which is %d days)'".