Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/C/Firefox/js/src/tests/non262/Intl/DurationFormat/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 1 kB image not shown  

Quelle  basic-zero.js   Sprache: JAVA

 
// |reftest| skip-if(!this.hasOwnProperty('Intl')||!Intl.hasOwnProperty("DurationFormat"))

// Test formatting zero amount for a single unit and compare "auto" against
// "always" for the display option.

const {
  Integer, Literal, Unit
} = NumberFormatParts;

function ToDurationFormatPart(unit) {
  unit = unit.slice(0, -1);
  unit = unit[0].toUpperCase() + unit.slice(1);
  return DurationFormatParts[unit];
}

const tests = {
  "en": Object.fromEntries(units.map(unit => [unit, unit])),
  "de": {
    "years""Jahre",
    "months""Monate",
    "weeks""Wochen",
    "days""Tage",
    "hours""Stunden",
    "minutes""Minuten",
    "seconds""Sekunden",
    "milliseconds""Millisekunden",
    "microseconds""Mikrosekunden",
    "nanoseconds""Nanosekunden",
  },
};

for (let [locale, data] of Object.entries(tests)) {
  for (let unit of units) {
    let auto = new Intl.DurationFormat(locale, {
      style: "long",
      [unit + "Display"]: "auto",
    });
    let always = new Intl.DurationFormat(locale, {
      style: "long",
      [unit + "Display"]: "always",
    });

    let duration = {[unit]: 0};
    let expected = `0 ${data[unit]}`;

    // Empty string.
    assertEq(auto.format(duration), "", `auto: ${unit}`);

    // Empty array.
    assertEq(auto.formatToParts(duration).length, 0, `auto: ${unit}`);

    assertEq(always.format(duration), expected, `always: ${unit}`);

    let parts = always.formatToParts(duration);
    assertEq(PartsToString(parts), expected, `always: ${unit}`);

    assertDeepEq(parts, [
      ...ToDurationFormatPart(unit)(Integer("0"), Literal(" "), Unit(data[unit])),
    ]);
  }
}

if (typeof reportCompare === "function")
  reportCompare(truetrue);

Messung V0.5
C=90 H=89 G=89

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.