//// //// YOU SHOULD NOT MODIFY THIS FILE //// //// (You don't need to submit it, either.) //// package cs3500.hw01.duration; import cs3500.lec11.StringAccumulator; /** * Durations, with a resolution of seconds. All durations are non-negative. * *
Different {@code Duration} implementations should work together, * meaning that: * *
The template is a string that may contain both fixed * text and some number of format specifiers, which are * special two-character codes starting with a {@code %} character. * This method returns a string that is like the template string, * with the fixed text copied unchanged and the format specifiers * replaced by textual representations of the indicated values for * {@code this} duration. * *
More precisely, a template is a sequence of uninterpreted * characters and two-character format specifiers. An uninterpreted * character may be any character but {@code '%'}. A format specifier * may be any of the two-character codes defined in the table below, * and nothing else. The result string is the concatenation of the * meanings of each of the elements of the template sequence, where * the meaning of an uninterpreted character is itself, and the * meaning of a format specifier is a string as defined in the table * below. * *
The above implies that in cases where two format specifiers * appear to overlap (e.g., {@code "%%t"}), the left-most * specifier takes precedence (so the result in this case would be * {@code "%t"}). Alternatively, we could say that the format * specifiers are interpreted from left to right, and the result of * converting a specifier is never interpreted a second time. * *
A template is malformed if it doesn't meet the definition of * template above. Another way to think of this is that in a * well-formed template, every {@code '%'} character is followed by * one of the eight characters that follow {@code %} in the table * below, except when it is the following character for another * {@code %}. * *
Format Specifier | *Meaning | *
---|---|
{@code %t} | the whole duration in seconds |
{@code %h} | the hours component of the decomposed * duration |
{@code %H} | the hours component of the decomposed * duration, padded to 2 digits with leading zeros (e.g., * {@code 05} or {@code 11}) |
{@code %m} | the minutes component of the decomposed * duration |
{@code %M} | the minutes component of the decomposed * duration, padded to 2 digits with leading zeros (e.g., * {@code 05} or {@code 56}) |
{@code %s} | the seconds component of the decomposed * duration |
{@code %S} | the seconds component of the decomposed * duration, padded to 2 digits with leading zeros (e.g., * {@code 05} or {@code 56}) |
{@code %%} | a literal percent sign ({@code %}) |