mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2025-04-05 19:42:07 +08:00
2 lines
8.6 KiB
JavaScript
2 lines
8.6 KiB
JavaScript
import{g as y,f as _}from"./date-fns@3.6.0-CG906D2E.js";function w(e,t,n){const r=y(),s=L(e,n.timeZone,n.locale??r.locale);return"formatToParts"in s?S(s,t):E(s,t)}function S(e,t){const n=e.formatToParts(t);for(let r=n.length-1;r>=0;--r)if(n[r].type==="timeZoneName")return n[r].value}function E(e,t){const n=e.format(t).replace(/\u200E/g,""),r=/ [\w-+ ]+$/.exec(n);return r?r[0].substr(1):""}function L(e,t,n){return new Intl.DateTimeFormat(n?[n.code,"en-US"]:void 0,{timeZone:t,timeZoneName:e})}function X(e,t){const n=k(t);return"formatToParts"in n?P(n,e):W(n,e)}const A={year:0,month:1,day:2,hour:3,minute:4,second:5};function P(e,t){try{const n=e.formatToParts(t),r=[];for(let s=0;s<n.length;s++){const i=A[n[s].type];i!==void 0&&(r[i]=parseInt(n[s].value,10))}return r}catch(n){if(n instanceof RangeError)return[NaN];throw n}}function W(e,t){const n=e.format(t),r=/(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(n);return[parseInt(r[3],10),parseInt(r[1],10),parseInt(r[2],10),parseInt(r[4],10),parseInt(r[5],10),parseInt(r[6],10)]}const D={},Y=new Intl.DateTimeFormat("en-US",{hourCycle:"h23",timeZone:"America/New_York",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).format(new Date("2014-06-25T04:00:00.123Z")),v=Y==="06/25/2014, 00:00:00"||Y==="06/25/2014 00:00:00";function k(e){return D[e]||(D[e]=v?new Intl.DateTimeFormat("en-US",{hourCycle:"h23",timeZone:e,year:"numeric",month:"numeric",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}):new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:e,year:"numeric",month:"numeric",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})),D[e]}function F(e,t,n,r,s,i,o){const a=new Date(0);return a.setUTCFullYear(e,t,n),a.setUTCHours(r,s,i,o),a}const h=36e5,j=6e4,d={timezone:/([Z+-].*)$/,timezoneZ:/^(Z)$/,timezoneHH:/^([+-]\d{2})$/,timezoneHHMM:/^([+-])(\d{2}):?(\d{2})$/};function I(e,t,n){if(!e)return 0;let r=d.timezoneZ.exec(e);if(r)return 0;let s,i;if(r=d.timezoneHH.exec(e),r)return s=parseInt(r[1],10),M(s)?-(s*h):NaN;if(r=d.timezoneHHMM.exec(e),r){s=parseInt(r[2],10);const o=parseInt(r[3],10);return M(s,o)?(i=Math.abs(s)*h+o*j,r[1]==="+"?-i:i):NaN}if(q(e)){t=new Date(t||Date.now());const o=n?t:R(t),a=g(o,e);return-(n?a:G(t,a,e))}return NaN}function R(e){return F(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())}function g(e,t){const n=X(e,t),r=F(n[0],n[1]-1,n[2],n[3]%24,n[4],n[5],0).getTime();let s=e.getTime();const i=s%1e3;return s-=i>=0?i:1e3+i,r-s}function G(e,t,n){let s=e.getTime()-t;const i=g(new Date(s),n);if(t===i)return t;s-=i-t;const o=g(new Date(s),n);return i===o?i:Math.max(i,o)}function M(e,t){return-23<=e&&e<=23&&(t==null||0<=t&&t<=59)}const O={};function q(e){if(O[e])return!0;try{return new Intl.DateTimeFormat(void 0,{timeZone:e}),O[e]=!0,!0}catch{return!1}}const B=60*1e3,J={X:function(e,t,n){const r=T(n.timeZone,e);if(r===0)return"Z";switch(t){case"X":return x(r);case"XXXX":case"XX":return l(r);case"XXXXX":case"XXX":default:return l(r,":")}},x:function(e,t,n){const r=T(n.timeZone,e);switch(t){case"x":return x(r);case"xxxx":case"xx":return l(r);case"xxxxx":case"xxx":default:return l(r,":")}},O:function(e,t,n){const r=T(n.timeZone,e);switch(t){case"O":case"OO":case"OOO":return"GMT"+Q(r,":");case"OOOO":default:return"GMT"+l(r,":")}},z:function(e,t,n){switch(t){case"z":case"zz":case"zzz":return w("short",e,n);case"zzzz":default:return w("long",e,n)}}};function T(e,t){const n=e?I(e,t,!0)/B:(t==null?void 0:t.getTimezoneOffset())??0;if(Number.isNaN(n))throw new RangeError("Invalid time zone specified: "+e);return n}function m(e,t){const n=e<0?"-":"";let r=Math.abs(e).toString();for(;r.length<t;)r="0"+r;return n+r}function l(e,t=""){const n=e>0?"-":"+",r=Math.abs(e),s=m(Math.floor(r/60),2),i=m(Math.floor(r%60),2);return n+s+t+i}function x(e,t){return e%60===0?(e>0?"-":"+")+m(Math.abs(e)/60,2):l(e,t)}function Q(e,t=""){const n=e>0?"-":"+",r=Math.abs(e),s=Math.floor(r/60),i=r%60;return i===0?n+String(s):n+String(s)+t+m(i,2)}function z(e){const t=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()));return t.setUTCFullYear(e.getFullYear()),+e-+t}const V=/(Z|[+-]\d{2}(?::?\d{2})?| UTC| [a-zA-Z]+\/[a-zA-Z_]+(?:\/[a-zA-Z_]+)?)$/,N=36e5,C=6e4,K=2,u={dateTimePattern:/^([0-9W+-]+)(T| )(.*)/,datePattern:/^([0-9W+-]+)(.*)/,plainTime:/:/,YY:/^(\d{2})$/,YYY:[/^([+-]\d{2})$/,/^([+-]\d{3})$/,/^([+-]\d{4})$/],YYYY:/^(\d{4})/,YYYYY:[/^([+-]\d{4})/,/^([+-]\d{5})/,/^([+-]\d{6})/],MM:/^-(\d{2})$/,DDD:/^-?(\d{3})$/,MMDD:/^-?(\d{2})-?(\d{2})$/,Www:/^-?W(\d{2})$/,WwwD:/^-?W(\d{2})-?(\d{1})$/,HH:/^(\d{2}([.,]\d*)?)$/,HHMM:/^(\d{2}):?(\d{2}([.,]\d*)?)$/,HHMMSS:/^(\d{2}):?(\d{2}):?(\d{2}([.,]\d*)?)$/,timeZone:V};function $(e,t={}){if(arguments.length<1)throw new TypeError("1 argument required, but only "+arguments.length+" present");if(e===null)return new Date(NaN);const n=t.additionalDigits==null?K:Number(t.additionalDigits);if(n!==2&&n!==1&&n!==0)throw new RangeError("additionalDigits must be 0, 1 or 2");if(e instanceof Date||typeof e=="object"&&Object.prototype.toString.call(e)==="[object Date]")return new Date(e.getTime());if(typeof e=="number"||Object.prototype.toString.call(e)==="[object Number]")return new Date(e);if(Object.prototype.toString.call(e)!=="[object String]")return new Date(NaN);const r=ee(e),{year:s,restDateString:i}=te(r.date,n),o=ne(i,s);if(o===null||isNaN(o.getTime()))return new Date(NaN);if(o){const a=o.getTime();let c=0,f;if(r.time&&(c=re(r.time),c===null||isNaN(c)))return new Date(NaN);if(r.timeZone||t.timeZone){if(f=I(r.timeZone||t.timeZone,new Date(a+c)),isNaN(f))return new Date(NaN)}else f=z(new Date(a+c)),f=z(new Date(a+c+f));return new Date(a+c+f)}else return new Date(NaN)}function ee(e){const t={};let n=u.dateTimePattern.exec(e),r;if(n?(t.date=n[1],r=n[3]):(n=u.datePattern.exec(e),n?(t.date=n[1],r=n[2]):(t.date=null,r=e)),r){const s=u.timeZone.exec(r);s?(t.time=r.replace(s[1],""),t.timeZone=s[1].trim()):t.time=r}return t}function te(e,t){if(e){const n=u.YYY[t],r=u.YYYYY[t];let s=u.YYYY.exec(e)||r.exec(e);if(s){const i=s[1];return{year:parseInt(i,10),restDateString:e.slice(i.length)}}if(s=u.YY.exec(e)||n.exec(e),s){const i=s[1];return{year:parseInt(i,10)*100,restDateString:e.slice(i.length)}}}return{year:null}}function ne(e,t){if(t===null)return null;let n,r,s;if(!e||!e.length)return n=new Date(0),n.setUTCFullYear(t),n;let i=u.MM.exec(e);if(i)return n=new Date(0),r=parseInt(i[1],10)-1,H(t,r)?(n.setUTCFullYear(t,r),n):new Date(NaN);if(i=u.DDD.exec(e),i){n=new Date(0);const o=parseInt(i[1],10);return oe(t,o)?(n.setUTCFullYear(t,0,o),n):new Date(NaN)}if(i=u.MMDD.exec(e),i){n=new Date(0),r=parseInt(i[1],10)-1;const o=parseInt(i[2],10);return H(t,r,o)?(n.setUTCFullYear(t,r,o),n):new Date(NaN)}if(i=u.Www.exec(e),i)return s=parseInt(i[1],10)-1,Z(s)?U(t,s):new Date(NaN);if(i=u.WwwD.exec(e),i){s=parseInt(i[1],10)-1;const o=parseInt(i[2],10)-1;return Z(s,o)?U(t,s,o):new Date(NaN)}return null}function re(e){let t,n,r=u.HH.exec(e);if(r)return t=parseFloat(r[1].replace(",",".")),p(t)?t%24*N:NaN;if(r=u.HHMM.exec(e),r)return t=parseInt(r[1],10),n=parseFloat(r[2].replace(",",".")),p(t,n)?t%24*N+n*C:NaN;if(r=u.HHMMSS.exec(e),r){t=parseInt(r[1],10),n=parseInt(r[2],10);const s=parseFloat(r[3].replace(",","."));return p(t,n,s)?t%24*N+n*C+s*1e3:NaN}return null}function U(e,t,n){t=t||0,n=n||0;const r=new Date(0);r.setUTCFullYear(e,0,4);const s=r.getUTCDay()||7,i=t*7+n+1-s;return r.setUTCDate(r.getUTCDate()+i),r}const se=[31,28,31,30,31,30,31,31,30,31,30,31],ie=[31,29,31,30,31,30,31,31,30,31,30,31];function b(e){return e%400===0||e%4===0&&e%100!==0}function H(e,t,n){if(t<0||t>11)return!1;if(n!=null){if(n<1)return!1;const r=b(e);if(r&&n>ie[t]||!r&&n>se[t])return!1}return!0}function oe(e,t){if(t<1)return!1;const n=b(e);return!(n&&t>366||!n&&t>365)}function Z(e,t){return!(e<0||e>52||t!=null&&(t<0||t>6))}function p(e,t,n){return!(e<0||e>=25||t!=null&&(t<0||t>=60)||n!=null&&(n<0||n>=60))}const ae=/([xXOz]+)|''|'(''|[^'])+('|$)/g;function ue(e,t,n={}){t=String(t);const r=t.match(ae);if(r){const s=$(n.originalDate||e,n);t=r.reduce(function(i,o){if(o[0]==="'")return i;const a=i.indexOf(o),c=i[a-1]==="'",f=i.replace(o,"'"+J[o[0]](s,o,n)+"'");return c?f.substring(0,a-1)+f.substring(a+1):f},t)}return _(e,t,n)}function ce(e,t,n){e=$(e,n);const r=I(t,e,!0),s=new Date(e.getTime()-r),i=new Date(0);return i.setFullYear(s.getUTCFullYear(),s.getUTCMonth(),s.getUTCDate()),i.setHours(s.getUTCHours(),s.getUTCMinutes(),s.getUTCSeconds(),s.getUTCMilliseconds()),i}function le(e,t,n,r){return r={...r,timeZone:t,originalDate:e},ue(ce(e,t,{timeZone:r.timeZone}),n,r)}export{le as f};
|