carbon-react
Version:
A library of reusable React components for easily building user interfaces.
2 lines (1 loc) • 2.25 kB
JavaScript
import{format as t}from"date-fns/fp/format";import{formatISO as n}from"date-fns/fp/formatISO";import{isMatch as r}from"date-fns/fp/isMatch";import{isValid as e}from"date-fns/fp/isValid";import{parse as i}from"date-fns/fp/parse";import{parseWithOptions as o}from"date-fns/fp/parseWithOptions";import{parseISO as f}from"date-fns/fp/parseISO";function u(t,n){const r=o({locale:n})(new Date,"P",t);return e(r)}function s(t,n){if(n&&t)return i(new Date,t,n)}function l(t){return t&&"Invalid Date"!==t.toString()}function c(t,r){const e=s(t,r);return e&&l(e)?n(e).split("T")[0]:null}function p(n,r){return r?t(n,r):""}function g(t,n){if(t.split("y").length-1!=2)return[t,n];const r=t.startsWith("yy"),e=r?0:n.length-2,i=r?2:n.length,o=r?i:0,f=r?n.length:n.length-2;let u=n.substring(e,i);const s=n.substring(o,f),l=Number(u);return u=String(l<69?2e3+l:1900+l),r?[`yyyy${t.substring(2,t.length)}`,`${u}${s}`]:[`${t.substring(0,t.length-2)}yyyy`,`${s}${u}`]}function a(t,n){return t.map(((r,e)=>n.substring(t[e],t[e+1])))}function h(t,n){return t.every(((e,i)=>function(t,n,e,i){return t.includes("d")?t.length===n.length&&r(e.join("."),i.join(".")):t.length===n.length&&r(t,n)}(e,n[i],t,n)))}const m=t=>["",".",",","-","/"," ",":"].slice(1).find((n=>t.includes(n)))||"";function d(t,n){if(!t)return["",""];const r=m(t),e=n.filter((n=>n.length===t.length&&m(n)===r)).reduce(((n,e)=>{const i=m(e);if(""===r&&""===i){const n=function(t,n){const r=n.split("").reduce(((t,r,e)=>0===e||r!==n[e-1]?[...t,e]:t),[]),e=a(r,n),i=a(r,t);return h(e,i)?[e.join(" "),i.join(" ")]:null}(t,e);if(n)return n}if(r&&i&&r===i){const n=function(t,n,r){return h(n.split(r),t.split(r))?[n,t]:null}(t,e,r);if(n)return n}return n}),[]);return e}function y(t){return f(t)}function b(t){if(10!==t.length||"Invalid Date"===y(t).toString())return!1;const n=t.split("-");return 3===n.length&&4===n[0].length&&2===n[1].length&&2===n[2].length}function $(t="",n=""){const r=[];if(t||n)return b(t)&&r.push({before:y(t)}),b(n)&&r.push({after:y(n)}),r}export{g as additionalYears,b as checkISOFormatAndLength,d as findMatchedFormatAndValue,c as formatToISO,p as formattedValue,$ as getDisabledDays,m as getSeparator,l as isDateValid,u as isValidLocaleDate,s as parseDate,y as parseISODate};