Skip to content

Docs: Duration object form does not list hour / hours (and week / weeks) as accepted keys #1

Description

@sieberlukas

Description

The Duration object documentation says that the object form accepts any of the following keys:

year, years, month, months, day, days, minute, minutes, second, seconds, millisecond, milliseconds, ms

The keys hour / hours and week / weeks are missing from this list, even though they are supported.

The list is incomplete in both versions of the docs:

Current source (v7.1.0)

In @full-ui/headless-calendar@7.1.0, createDuration() passes object input to parseObject(), which accepts hour / hours and week / weeks:

function parseObject(obj) {
    let duration = {
        years: obj.years || obj.year || 0,
        months: obj.months || obj.month || 0,
        days: obj.days || obj.day || 0,
        milliseconds: (obj.hours || obj.hour || 0) * 60 * 60 * 1000 + // hours
            (obj.minutes || obj.minute || 0) * 60 * 1000 + // minutes
            (obj.seconds || obj.second || 0) * 1000 + // seconds
            (obj.milliseconds || obj.millisecond || obj.ms || 0), // ms
    };
    let weeks = obj.weeks || obj.week;
    if (weeks) {
        duration.days += weeks * 7;
        duration.specifiedWeeks = true;
    }
    return duration;
}

The published TypeScript type also includes these keys:

interface DurationObjectInput {
    years?: number;
    year?: number;
    months?: number;
    month?: number;
    weeks?: number;
    week?: number;
    days?: number;
    day?: number;
    hours?: number;
    hour?: number;
    minutes?: number;
    minute?: number;
    seconds?: number;
    second?: number;
    milliseconds?: number;
    millisecond?: number;
    ms?: number;
}

v6 behaves the same way (checked in 6.1.15).

Example

This works as expected, but going by the docs it doesn't look valid:

new Calendar(el, {
  slotMinTime: { hours: 6 },
  slotMaxTime: { hours: 22 },
});

Suggested fix

Update the list of accepted keys in the object form (in both the v7 and v6 docs) to:

year, years, month, months, week, weeks, day, days, hour, hours, minute, minutes, second, seconds, millisecond, milliseconds, ms

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions