Functional Weave
Code in Rust

time.duration@1.0.0

vectors.json

2,870 bytes · view raw

[
  {"name": "hours and minutes", "args": [["1h30m"]], "expect": {"minutes": 90, "text": "1h30m", "clock": "01:30"}},
  {"name": "minutes alone may be 60 or more", "args": [["90m"]], "expect": {"minutes": 90, "text": "1h30m", "clock": "01:30"}},
  {"name": "clock form", "args": [["01:30"]], "expect": {"minutes": 90, "text": "1h30m", "clock": "01:30"}},
  {"name": "clock form without a leading zero", "args": [["1:30"]], "expect": {"minutes": 90, "text": "1h30m", "clock": "01:30"}},
  {"name": "a space between hours and minutes", "args": [["1h 30m"]], "expect": {"minutes": 90, "text": "1h30m", "clock": "01:30"}},
  {"name": "whole hours format without minutes", "args": [["2h"]], "expect": {"minutes": 120, "text": "2h", "clock": "02:00"}},
  {"name": "under an hour", "args": [["45m"]], "expect": {"minutes": 45, "text": "45m", "clock": "00:45"}},
  {"name": "a timesheet in mixed forms adds up", "args": [["1h30m", "45m", "0:15"]], "expect": {"minutes": 150, "text": "2h30m", "clock": "02:30"}},
  {"name": "an empty list is zero", "args": [[]], "expect": {"minutes": 0, "text": "0m", "clock": "00:00"}},
  {"name": "zero minutes", "args": [["0m"]], "expect": {"minutes": 0, "text": "0m", "clock": "00:00"}},
  {"name": "more than a day does not wrap at 24 hours", "args": [["25:30"]], "expect": {"minutes": 1530, "text": "25h30m", "clock": "25:30"}},
  {"name": "upper case units and surrounding spaces are accepted", "args": [[" 1H30M "]], "expect": {"minutes": 90, "text": "1h30m", "clock": "01:30"}},
  {"name": "a three-digit hour clock", "args": [["100:00"]], "expect": {"minutes": 6000, "text": "100h", "clock": "100:00"}},
  {"name": "minutes that sum past the hour carry into hours", "args": [["40m", "40m"]], "expect": {"minutes": 80, "text": "1h20m", "clock": "01:20"}},
  {"name": "a bare number is ambiguous and rejected", "args": [["90"]], "expectError": "\"90\" is not a duration"},
  {"name": "decimal hours are rejected", "args": [["1.5h"]], "expectError": "\"1.5h\" is not a duration"},
  {"name": "minutes of 60 or more beside hours is an error", "args": [["1h90m"]], "expectError": "minutes must be under 60 when hours are given"},
  {"name": "a clock minute of 75 is an error", "args": [["1:75"]], "expectError": "minutes must be under 60 when hours are given"},
  {"name": "a single clock minute digit is rejected", "args": [["1:5"]], "expectError": "\"1:5\" is not a duration"},
  {"name": "units in the wrong order are rejected", "args": [["30m1h"]], "expectError": "\"30m1h\" is not a duration"},
  {"name": "an empty string is not a duration", "args": [[""]], "expectError": "\"\" is not a duration"},
  {"name": "a negative duration is rejected", "args": [["-15m"]], "expectError": "\"-15m\" is not a duration"},
  {"name": "one bad part fails the whole total", "args": [["1h", "soon"]], "expectError": "\"soon\" is not a duration"}
]