"Fossies" - the Fresh Open Source Software Archive

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

Caution: As a special service "Fossies" has tried to format the requested Texinfo source page into HTML format but that may be not always succeeeded perfectly. Alternatively you can here view or download the uninterpreted Texinfo source code. A member file download can also be achieved by clicking within a package contents listing on the according byte size field. See also the last Fossies "Diffs" side-by-side code changes report for "format-ddiff.texi": 0.4.2_vs_0.4.3.

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1 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:

  %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

Time specs:

  %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

General specs:

  %n  A newline character
  %t  A tab character
  %%  A literal % character


  %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

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2 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 ‘%S’ as ‘128’ but similarly through ‘%M:%S’ as ‘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.

  %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

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 ‘%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. ‘'%w weeks (which is %d days)'’.

[Top] [Contents] [Index] [ ? ]

About This Document

This document was generated on March 25, 2019 using texi2html.

The buttons in the navigation panels have the following meaning:

Button Name Go to From 1.2.3 go to
[ << ] FastBack Beginning of this chapter or previous chapter 1
[ < ] Back Previous section in reading order 1.2.2
[ Up ] Up Up section 1.2
[ > ] Forward Next section in reading order 1.2.4
[ >> ] FastForward Next chapter 2
[Top] Top Cover (top) of document  
[Contents] Contents Table of contents  
[Index] Index Index  
[ ? ] About About (help)  

where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:

This document was generated on March 25, 2019 using texi2html.