Sha256: 6c4aecbcfff94904affbc46e2a2ed2bc3a046ca8133d3c025a658877e1867d82

Contents?: true

Size: 1.24 KB

Versions: 26

Compression:

Stored size: 1.24 KB

Contents

const parseInt = globalThis.parseInt;
function buildTimeValue(value) {
    const onlyDigitsValue = value.replace(/\D/g, '');
    if (onlyDigitsValue.length < 2) {
        return value;
    }
    const firstDigit = parseInt(onlyDigitsValue[0], 10);
    const secondDigit = parseInt(onlyDigitsValue[1], 10);
    if (firstDigit >= 3 || firstDigit === 2 && secondDigit >= 4) {
        let index;
        if (firstDigit >= 3) {
            index = 1;
        } else {
            index = 2;
        }
        return build(onlyDigitsValue, index);
    }
    if (value.length === 2) {
        return value;
    }
    return build(onlyDigitsValue, 2);
}
function build(onlyDigitsValue, index) {
    const hours = onlyDigitsValue.slice(0, index);
    const validHours = Math.min(parseInt(hours, 10), 23);
    const minuteCharacters = onlyDigitsValue.slice(index);
    const parsedMinutes = parseInt(minuteCharacters, 10);
    const validMinutes = Math.min(parsedMinutes, 59);
    return `${validHours.toString().padStart(2, '0')}:${validMinutes.toString().padStart(2, '0')}`;
}
function isValidDateOrTimeValue(element, value) {
    const clone = element.cloneNode();
    clone.value = value;
    return clone.value === value;
}

export { buildTimeValue, isValidDateOrTimeValue };

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/utils/edit/timeValue.js