UNPKG

@ionic/core

Version:
4 lines • 8.17 kB
/*! * (C) Ionic http://ionicframework.com - MIT License */ import{a as n}from"./p-BpRUsN_W.js";const e=(n,e)=>n.month===e.month&&n.day===e.day&&n.year===e.year,r=(n,e)=>!!(n.year<e.year||n.year===e.year&&n.month<e.month||n.year===e.year&&n.month===e.month&&null!==n.day&&n.day<e.day),t=(n,e)=>!!(n.year>e.year||n.year===e.year&&n.month>e.month||n.year===e.year&&n.month===e.month&&null!==n.day&&n.day>e.day),o=(e,o,a)=>{const i=Array.isArray(e)?e:[e];for(const d of i)if(void 0!==o&&r(d,o)||void 0!==a&&t(d,a)){n(`[ion-datetime] - The value provided to ion-datetime is out of bounds.\n\nMin: ${JSON.stringify(o)}\nMax: ${JSON.stringify(a)}\nValue: ${JSON.stringify(e)}`);break}},a=(n,e)=>{if(void 0!==e)return e;const r=new Intl.DateTimeFormat(n,{hour:"numeric"}),t=r.resolvedOptions();if(void 0!==t.hourCycle)return t.hourCycle;const o=new Date("5/18/2021 00:00"),a=r.formatToParts(o).find((n=>"hour"===n.type));if(!a)throw new Error("Hour value not found from DateTimeFormat");switch(a.value){case"0":return"h11";case"12":return"h12";case"00":return"h23";case"24":return"h24";default:throw new Error(`Invalid hour cycle "${e}"`)}},i=n=>"h23"===n||"h24"===n,d=(n,e)=>4===n||6===n||9===n||11===n?30:2===n?(n=>n%4==0&&n%100!=0||n%400==0)(e)?29:28:31,s=(n,e={month:"numeric",year:"numeric"})=>"month"===new Intl.DateTimeFormat(n,e).formatToParts(new Date)[0].type,u=n=>"dayPeriod"===new Intl.DateTimeFormat(n,{hour:"numeric"}).formatToParts(new Date)[0].type,m=/^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?::(\d{2}))?)?)?$/,c=/^((\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?::(\d{2}))?)?)?$/,v=n=>{if(void 0===n)return;let e,r=n;return"string"==typeof n&&(r=n.replace(/\[|\]|\s/g,"").split(",")),e=Array.isArray(r)?r.map((n=>parseInt(n,10))).filter(isFinite):[r],e},y=n=>({month:parseInt(n.getAttribute("data-month"),10),day:parseInt(n.getAttribute("data-day"),10),year:parseInt(n.getAttribute("data-year"),10),dayOfWeek:parseInt(n.getAttribute("data-day-of-week"),10)});function l(e){if(Array.isArray(e)){const n=[];for(const r of e){const e=l(r);if(!e)return;n.push(e)}return n}let r=null;if(null!=e&&""!==e&&(r=c.exec(e),r?(r.unshift(void 0,void 0),r[2]=r[3]=void 0):r=m.exec(e)),null!==r){for(let n=1;n<8;n++)r[n]=void 0!==r[n]?parseInt(r[n],10):void 0;return{year:r[1],month:r[2],day:r[3],hour:r[4],minute:r[5],ampm:r[4]<12?"am":"pm"}}n(`[ion-datetime] - Unable to parse date string: ${e}. Please provide a valid ISO 8601 datetime string.`)}const h=(n,e,o)=>e&&r(n,e)?e:o&&t(n,o)?o:n,f=n=>n>=12?"pm":"am",w=(n,e)=>{const r=l(n);if(void 0===r)return;const{month:t,day:o,year:a,hour:i,minute:s}=r,u=a??e.year,m=t??12;return{month:m,day:o??d(m,u),year:u,hour:i??23,minute:s??59}},p=(n,e)=>{const r=l(n);if(void 0===r)return;const{month:t,day:o,year:a,hour:i,minute:d}=r;return{month:t??1,day:o??1,year:a??e.year,hour:i??0,minute:d??0}},I=n=>("0"+(void 0!==n?Math.abs(n):"0")).slice(-2);function $(n){if(Array.isArray(n))return n.map((n=>$(n)));let e="";var r;return void 0!==n.year?(e=("000"+(void 0!==(r=n.year)?Math.abs(r):"0")).slice(-4),void 0!==n.month&&(e+="-"+I(n.month),void 0!==n.day&&(e+="-"+I(n.day),void 0!==n.hour&&(e+=`T${I(n.hour)}:${I(n.minute)}:00`)))):void 0!==n.hour&&(e=I(n.hour)+":"+I(n.minute)),e}const T=(n,e)=>void 0===e?n:"am"===e?12===n?0:n:12===n?12:n+12,k=n=>{const{dayOfWeek:e}=n;if(null==e)throw new Error("No day of week provided");return g(n,e)},N=n=>{const{dayOfWeek:e}=n;if(null==e)throw new Error("No day of week provided");return E(n,6-e)},D=n=>E(n,1),M=n=>g(n,1),O=n=>g(n,7),Z=n=>E(n,7),g=(n,e)=>{const{month:r,day:t,year:o}=n;if(null===t)throw new Error("No day provided");const a={month:r,day:t,year:o};if(a.day=t-e,a.day<1&&(a.month-=1),a.month<1&&(a.month=12,a.year-=1),a.day<1){const n=d(a.month,a.year);a.day=n+a.day}return a},E=(n,e)=>{const{month:r,day:t,year:o}=n;if(null===t)throw new Error("No day provided");const a={month:r,day:t,year:o},i=d(r,o);return a.day=t+e,a.day>i&&(a.day-=i,a.month+=1),a.month>12&&(a.month=1,a.year+=1),a},C=n=>{const e=1===n.month?12:n.month-1,r=1===n.month?n.year-1:n.year,t=d(e,r);return{month:e,year:r,day:t<n.day?t:n.day}},P=n=>{const e=12===n.month?1:n.month+1,r=12===n.month?n.year+1:n.year,t=d(e,r);return{month:e,year:r,day:t<n.day?t:n.day}},U=(n,e)=>{const r=n.month,t=n.year+e,o=d(r,t);return{month:r,year:t,day:o<n.day?o:n.day}},A=n=>U(n,-1),V=n=>U(n,1),W=(n,e,r)=>e?n:T(n,r),b=(n,e)=>{const{ampm:r,hour:t}=n;let o=t;return"am"===r&&"pm"===e?o=T(o,"pm"):"pm"===r&&"am"===e&&(o=Math.abs(o-12)),o},x=(n,r,t)=>{const{month:o,day:a,year:i}=n,s=h({...n},r,t),u=d(o,i);return null!==a&&u<a&&(s.day=u),void 0!==r&&e(s,r)&&void 0!==s.hour&&void 0!==r.hour&&(s.hour<r.hour?(s.hour=r.hour,s.minute=r.minute):s.hour===r.hour&&void 0!==s.minute&&void 0!==r.minute&&s.minute<r.minute&&(s.minute=r.minute)),void 0!==t&&e(n,t)&&void 0!==s.hour&&void 0!==t.hour&&(s.hour>t.hour?(s.hour=t.hour,s.minute=t.minute):s.hour===t.hour&&void 0!==s.minute&&void 0!==t.minute&&s.minute>t.minute&&(s.minute=t.minute)),s},F=({refParts:n,monthValues:o,dayValues:a,yearValues:i,hourValues:d,minuteValues:s,minParts:u,maxParts:m})=>{const{hour:c,minute:v,day:y,month:l,year:h}=n,w={...n,dayOfWeek:void 0};if(void 0!==i){const n=i.filter((n=>!(void 0!==u&&n<u.year||void 0!==m&&n>m.year)));w.year=J(h,n)}if(void 0!==o){const n=o.filter((n=>!(void 0!==u&&w.year===u.year&&n<u.month||void 0!==m&&w.year===m.year&&n>m.month)));w.month=J(l,n)}if(null!==y&&void 0!==a){const n=a.filter((n=>!(void 0!==u&&r({...w,day:n},u)||void 0!==m&&t({...w,day:n},m))));w.day=J(y,n)}if(void 0!==c&&void 0!==d){const n=d.filter((n=>!(void 0!==u?.hour&&e(w,u)&&n<u.hour||void 0!==m?.hour&&e(w,m)&&n>m.hour)));w.hour=J(c,n),w.ampm=f(w.hour)}if(void 0!==v&&void 0!==s){const n=s.filter((n=>!(void 0!==u?.minute&&e(w,u)&&w.hour===u.hour&&n<u.minute||void 0!==m?.minute&&e(w,m)&&w.hour===m.hour&&n>m.minute)));w.minute=J(v,n)}return w},J=(n,e)=>{let r=e[0],t=Math.abs(r-n);for(let o=1;o<e.length;o++){const a=e[o],i=Math.abs(a-n);i<t&&(r=a,t=i)}return r},S=n=>({...n,timeZone:"UTC",timeZoneName:void 0}),j=(n,e,r,t={hour:"numeric",minute:"numeric"})=>{const o={hour:e.hour,minute:e.minute};return void 0===o.hour||void 0===o.minute?"Invalid Time":new Intl.DateTimeFormat(n,{...S(t),hourCycle:r}).format(new Date($({year:2023,day:1,month:1,...o})+"Z"))},B=n=>{const e=n.toString();return e.length>1?e:`0${e}`},G=(n,e)=>{if(0===n)switch(e){case"h11":return"0";case"h12":return"12";case"h23":return"00";case"h24":return"24";default:throw new Error(`Invalid hour cycle "${e}"`)}return i(e)?B(n):n.toString()},H=(n,e,r)=>{if(null===r.day)return null;const t=K(r),o=new Intl.DateTimeFormat(n,{weekday:"long",month:"long",day:"numeric",timeZone:"UTC"}).format(t);return e?`Today, ${o}`:o},R=(n,e)=>{const r=K(e);return new Intl.DateTimeFormat(n,{month:"long",year:"numeric",timeZone:"UTC"}).format(r)},q=(n,e)=>Q(n,e,{day:"numeric"}).find((n=>"day"===n.type)).value,z=(n,e)=>L(n,e,{year:"numeric"}),K=n=>new Date(`${n.month??1}/${n.day??1}/${n.year??2023}${void 0!==n.hour&&void 0!==n.minute?` ${n.hour}:${n.minute}`:""} GMT+0000`),L=(n,e,r)=>{const t=K(e);return _(n,S(r)).format(t)},Q=(n,e,r)=>{const t=K(e);return _(n,r).formatToParts(t)},_=(n,e)=>new Intl.DateTimeFormat(n,{...e,timeZone:"UTC"}),X=n=>{if("RelativeTimeFormat"in Intl){const e=new Intl.RelativeTimeFormat(n,{numeric:"auto"}).format(0,"day");return e.charAt(0).toUpperCase()+e.slice(1)}return"Today"},Y=n=>{const e=n.getTimezoneOffset();return n.setMinutes(n.getMinutes()-e),n},nn=Y(new Date("2022T01:00")),en=Y(new Date("2022T13:00")),rn=(n,e)=>{const r="am"===e?nn:en,t=new Intl.DateTimeFormat(n,{hour:"numeric",timeZone:"UTC"}).formatToParts(r).find((n=>"dayPeriod"===n.type));return t?t.value:(n=>void 0===n?"":n.toUpperCase())(e)},tn=n=>Array.isArray(n)?n.join(","):n;export{Z as A,p as B,w as C,l as D,o as E,f as F,h as G,v as H,$ as I,F as J,s as K,u as L,b as M,R as N,j as O,L as P,tn as Q,C as a,X as b,z as c,a as d,W as e,G as f,P as g,B as h,rn as i,r as j,e as k,t as l,i as m,d as n,q as o,H as p,y as q,Y as r,V as s,A as t,N as u,x as v,k as w,M as x,D as y,O as z}