UNPKG

gnablib

Version:

A lean, zero dependency library to provide a useful base for your project.

2 lines 40 kB
/*! Copyright 2024 the gnablib contributors MPL-1.1 */ import{ContentError as t}from"../error/ContentError.js";import{parseDec as e}from"../primitive/number/xtInt.js";import{Duration as n,DurationExact as r}from"./Duration.js";import{sNum as i}from"../safe/safe.js";const s=Symbol.for("nodejs.util.inspect.custom"),o=10,a=15,u=10,w=20,c=-1e4,h=22767,f=86400,m=3600,l=864e5,d=36e5,g=6e4,_=1e3,p=864e8,D=36e8,y=6e7,B=1e6,U=[0,31,28,31,30,31,30,31,31,30,31,30,31],M=146097,T=719468,x=!0;function S(t,e){return t.getUint16(e,x)-1e4}function V(t,e,n){t.setUint16(e,n+1e4,x)}function O(t,e){return t.getUint8(e)+1}function A(t,e,n){t.setUint8(e,n-1)}function N(t,e){return t.getUint8(e)+1}function b(t,e,n){t.setUint8(e,n-1)}function v(t,e,n,r,i){b(t,e,i),A(t,e+1,r),V(t,e+2,n)}function k(t,e){return[S(t,e+2),O(t,e+1),N(t,e)]}function E(t,e,n){n.mustPushNumberBE(t.getUint8(e),5),n.mustPushNumberBE(t.getUint8(e+1),4),n.mustPushNumberBE(t.getUint16(e+2,x),a)}function z(t,e,n){t.setUint8(e,n.readNumberBE(5)),t.setUint8(e+1,n.readNumberBE(4)),t.setUint16(e+2,n.readNumberBE(a),x)}function L(t,e){return t.getUint8(e)}function F(t,e,n){t.setUint8(e,n)}function H(t,e){return t.getUint8(e)}function Y(t,e,n){t.setUint8(e,n)}function $(t,e){return t.getUint8(e)}function C(t,e,n){t.setUint8(e,n)}function P(t,e){return t.getUint16(e,x)}function J(t,e,n){t.setUint16(e,n,x)}function R(t,e){return t.getUint16(e,x)|t.getUint8(e+2)<<16}function I(t,e,n){t.setUint16(e,n,x),t.setUint8(e+2,n>>16)}function j(t,e){return[L(t,e+4),H(t,e+3),$(t,e+2),P(t,e)]}function q(t,e,n,r,i,s){J(t,e,s),C(t,e+2,i),Y(t,e+3,r),F(t,e+4,n)}function Z(t,e){return[L(t,e+5),H(t,e+4),$(t,e+3),R(t,e)]}function G(t,e,n,r,i,s){I(t,e,s),C(t,e+3,i),Y(t,e+4,r),F(t,e+5,n)}function W(t,e,n){n.mustPushNumberBE(t.getUint16(e,x)|t.getUint8(e+2)<<16,w),n.mustPushNumberBE(t.getUint8(e+3),6),n.mustPushNumberBE(t.getUint8(e+4),6),n.mustPushNumberBE(t.getUint8(e+5),5)}function K(t,e,n){I(t,e,n.readNumberBE(w)),t.setUint8(e+3,n.readNumberBE(6)),t.setUint8(e+4,n.readNumberBE(6)),t.setUint8(e+5,n.readNumberBE(5))}class Q{constructor(t,e=0){this._d=t,this._pos=e}_year_iso(t){let e=S(this._d,t),n="";e>9999?n="+":e<0&&(n="-",e=-e);let r=e.toString();return r.length<4&&(r=("0000"+r).substring(r.length)),n+r}_month_iso(t){const e=O(this._d,t).toString();return("00"+e).substring(e.length)}_day_iso(t){const e=N(this._d,t).toString();return("00"+e).substring(e.length)}_date_iso(t,e){return this._year_iso(t+2)+e+this._month_iso(t+1)+e+this._day_iso(t)}_hour_iso(t){const e=L(this._d,t).toString();return("00"+e).substring(e.length)}_minute_iso(t){const e=H(this._d,t).toString();return("00"+e).substring(e.length)}_second_iso(t){const e=$(this._d,t).toString();return("00"+e).substring(e.length)}_milli_iso(t){const e=P(this._d,t).toString();return("000"+e).substring(e.length)}_micro_iso(t){const e=R(this._d,t).toString();return("000000"+e).substring(e.length)}_time_iso(t,e){let n="",r="";return e&&(n=":",r="."),this._hour_iso(t+5)+n+this._minute_iso(t+4)+n+this._second_iso(t+3)+r+this._micro_iso(t)}_date_valid(t){const[e,n,r]=k(this._d,t);i("month",n).atMost(12).throwNot(),i("day",r).atMost(Month.lastDay(n,e)).throwNot()}_time_valid(t){const[e,n,r,s]=Z(this._d,t);i("hour",e).lt(24).throwNot(),i("minute",n).lt(60).throwNot(),i("second",r).lt(60).throwNot(),i("microsecond",s).lt(B).throwNot()}toUnixDays(t){let[e,n,r]=k(this._d,t);n>2?n-=3:(n+=9,e-=1);const i=(e>=0?e:e-399)/400|0,s=e-400*i;return i*M+(365*s+(s/4|0)-(s/100|0)+((153*n+2)/5+r-1|0))-T}timeToUs(t){const[e,n,r,i]=Z(this._d,t);return e*D+n*y+r*B+i}static vetDate(t,e,n){i("year",t).atLeast(c).atMost(h).throwNot(),i("month",e).natural().atMost(12).throwNot(),i("day",n).natural().atMost(Month.lastDay(e,t)).throwNot()}static vetTime(t,e,n,r){i("hour",t).unsigned().lt(24).throwNot(),i("minute",e).unsigned().lt(60).throwNot(),i("second",n).unsigned().lt(60).throwNot(),i("microsecond",r).unsigned().lt(B).throwNot()}static parseYear(n,r,i,s,o){const a=i.match(/^([+-])?(\d+)$/);if(null!=a){const[,u,w]=a;if(s&&(w.length>5||5==w.length&&null==u||w.length<4))return o(),new t("expecting 4 digits zero padded or 5 digits with mandatory sign","input",i);let f=e(w);if(!Number.isNaN(f)&&(u&&(i.shrink(1),"-"===u&&(f=0-f)),f>=c&&f<=h))return i.shrink(w.length),void V(n,r,f)}return o(),new t("expecting signed integer-string","year",i)}static parseMonth(n,r,i,s,o){const a=i.match(/^(?:([\p{Alphabetic}\p{Mark}\p{Join_Control}]{3,})|(\d+))$/u);if(null!=a){const[,u,w]=a;if(null!=u){const t=Date.parse(u+" 16, 2000");if(!Number.isNaN(t))return i.shrink(u.length),void A(n,r,new Date(t).getMonth()+1)}else{if(s&&2!=w.length)return o(),new t("expecting 2 digit unsigned integer-string","month",i);const a=e(w);if(a>=1&&a<=12)return A(n,r,a),void i.shrink(w.length)}}return o(),new t("expecting unsigned integer-string, or short-form month","month",i)}static parseDay(n,r,i,s,o){const a=i.match(/^(\d+)$/);if(null!=a){const[,u]=a;if(s&&2!=u.length)return o(),new t("expecting 2 digit unsigned integer-string","day",i);const w=e(u);if(w>=1&&w<=31)return i.shrink(u.length),void n.setUint8(r,w-1)}return o(),new t("expecting 1-2 digit unsigned integer-string","day",i)}static parseDateUndelim(t,e,n,r,s){let o=Q.parseYear(t,e+2,n.left(n.length-4),r,s);if(o)return o;if(n.shrink(n.length-4),o=Q.parseMonth(t,e+1,n.left(2),r,s),o)return o;if(n.shrink(2),o=Q.parseDay(t,e,n,r,s),o)return o;const[a,u,w]=k(t,e),c=Month.lastDay(u,a);i("day",w).atMost(c).throwNot(),n.shrink(n.length)}static parseDate(e,n,r,s,o){if(r.test(/^[-+]?\d{8,9}$/))return Q.parseDateUndelim(e,n,r,s,o);let a,u;u=s?r.indexOf("-",1):r.indexOfAny(["-","/","."],1);let w="";u>0&&(w=r.charAt(u));const c=r.indexOf(w,u+1)-u-1;if(c>0){if(a=Q.parseYear(e,n+2,r.left(u).trimEnd(),s,o),a)return a;if(r.shrink(u+1),a=Q.parseMonth(e,n+1,r.left(c).trim(),s,o),a)return a;if(r.shrink(c+1),a=Q.parseDay(e,n,r.trim(),s,o),a)return a;const[t,w,h]=k(e,n),f=Month.lastDay(w,t);return i("day",h).atMost(f).throwNot(),void r.shrink(r.length)}return o(),new t(`Expecting 8-9 digit ymd (with optional sign), or ${w} delimited date`,"date",r)}static parseHour(n,r,i,s,o){const a=i.match(/^(\d+)$/);if(null!=a){const[,u]=a;if(s&&2!=u.length)return o(),new t("expecting 2 digit unsigned integer-string","hour",i);const w=e(u);if(w>=0&&w<=23)return i.shrink(u.length),void n.setUint8(r,w)}return o(),new t("expecting unsigned integer-string","hour",i)}static parseMinute(n,r,i,s,o){const a=i.match(/^(\d+)$/);if(null!=a){const[,u]=a;if(s&&2!=u.length)return o(),new t("expecting 2 digit unsigned integer-string","minute",i);const w=e(u);if(w>=0&&w<=59)return i.shrink(u.length),void n.setUint8(r,w)}return o(),new t("expecting unsigned integer-string","minute",i)}static parseSecond(n,r,i,s,o){const a=i.match(/^(\d+)$/);if(null!=a){const[,u]=a;if(s&&2!=u.length)return o(),new t("expecting 2 digit unsigned integer-string","second",i);const w=e(u);if(w>=0&&w<=59)return i.shrink(u.length),void n.setUint8(r,w)}return o(),new t("expecting unsigned integer-string","second",i)}static parseMilli(n,r,i,s,o,a){const u=i.match(/^(\d+)$/);if(null!=u){const[,w]=u;let c=w;if(s&&3!=w.length)return a(),new t("expecting 3 digit unsigned integer-string","millisecond",i);w.length<3&&o&&(c=(w+"000").substring(0,3));const h=e(c);if(h>=0&&h<=999)return i.shrink(w.length),void J(n,r,h)}return a(),new t("expecting unsigned integer-string","millisecond",i)}static parseMicro(n,r,i,s,o,a){const u=i.match(/^(\d+)$/);if(null!=u){const[,w]=u;let c=w;if(s&&6!=w.length)return a(),new t("expecting 6 digit unsigned integer-string","microsecond",i);w.length<6&&o&&(c=(w+"000000").substring(0,6));const h=e(c);if(h>=0&&h<=999999)return i.shrink(w.length),void I(n,r,h)}return a(),new t("expecting unsigned integer-string","microsecond",i)}static parseTimeUndelim(t,e,n,r,i){let s=Q.parseHour(t,e+5,n.left(2),r,i);return s||(n.shrink(2),s=Q.parseMinute(t,e+4,n.left(2),r,i),s||(n.shrink(2),s=Q.parseSecond(t,e+3,n.left(2),r,i),s||(n.shrink(2),s=Q.parseMicro(t,e,n,r,!1,i),s||void n.shrink(n.length))))}static parseTime(e,n,r,i,s){let o;if(r.test(/^\d{12}$/))return Q.parseTimeUndelim(e,n,r,i,s);const a=r.indexOf(":");let u=r.indexOf(":",a+1),w=r.indexOf(".",u+1);return w-=u+1,u-=a+1,a>0&&u>0&&w>0?(o=Q.parseHour(e,n+5,r.left(a).trim(),i,s),o||(r.shrink(a+1),o=Q.parseMinute(e,n+4,r.left(u).trim(),i,s),o||(r.shrink(u+1),o=Q.parseSecond(e,n+3,r.left(w).trim(),i,s),o||(r.shrink(w+1),o=Q.parseMicro(e,n,r.trim(),i,!0,s),o||void r.shrink(r.length))))):(s(),new t("Expecting hh:mm:ss.uuuuuu, or hhmmssuuuuuu","time",r))}static dateFromValue(t,e,n){const r=n%100,i=(n=(n-r)/100)%100;n=(n-i)/100,Q.vetDate(n,i,r),v(t,e,n,i,r)}static timeFromValue(t,e,n){const r=n%1e6,i=(n=(n-r)/1e6)%100,s=(n=(n-i)/100)%100;n=(n-s)/100,Q.vetTime(n,s,i,r),G(t,e,n,s,i,r)}static dateFromUnixDays(t,e,n){const r=((n=n+T|0)>=0?n:n-M+1)/M|0,i=n-r*M,s=(i-(i/1460|0)+(i/36524|0)-(i/146096|0))/365|0;let o=s+400*r;const a=i-365*s-(s/4|0)+(s/100|0),u=(5*a+2)/153|0,w=u<10?u+3:u-9;w<=2&&(o+=1),v(t,e,o,w,a+1-((153*u+2)/5|0))}}export class Year extends Q{static get min(){return X}static get max(){return tt}toString(){return S(this._d,this._pos).toString()}toIsoString(){return this._year_iso(this._pos)}toJSON(){return S(this._d,this._pos)}valueOf(){return S(this._d,this._pos)}serialize(t){t.mustPushNumberBE(this._d.getUint16(this._pos,x),a)}get serialSizeBits(){return a}get[Symbol.toStringTag](){return"Year"}[s](){return`Year(${S(this._d,this._pos)})`}static new(t){i("year",t).atLeast(c).atMost(h).throwNot();const e=new DataView(new ArrayBuffer(2));return V(e,0,t),new Year(e)}static newGregorian(t,e=!0){const n=new DataView(new ArrayBuffer(2));return e?(i("year",t).natural().atMost(h).throwNot(),V(n,0,t)):(i("-year",t).natural().atMost(10001).throwNot(),V(n,0,1-t)),new Year(n)}static newHolocene(t){i("year",t).unsigned().atMost(32767).throwNot();const e=new DataView(new ArrayBuffer(2));return V(e,0,t-1e4),new Year(e)}static fromDate(t){const e=new DataView(new ArrayBuffer(2));return V(e,0,t.getFullYear()),new Year(e)}static fromDateUtc(t){const e=new DataView(new ArrayBuffer(2));return V(e,0,t.getUTCFullYear()),new Year(e)}static parse(t,e=!1){const n=new DataView(new ArrayBuffer(2)),r=t.getReset();if(t.trim(),"now"==t.toString().toLowerCase())t.shrink(3),V(n,0,(new Date).getFullYear());else{const i=Q.parseYear(n,0,t,e,r);if(i)throw i}return new Year(n)}static now(){const t=new DataView(new ArrayBuffer(2));return V(t,0,(new Date).getFullYear()),new Year(t)}static isLeap(t){return!(3&(t|=0))&&(!(15&t)||t%25!=0)}static deserialize(t){const e=new DataView(new ArrayBuffer(2));return e.setUint16(0,t.readNumberBE(a),x),new Year(e)}}Year.storageBytes=2,Year.serialBits=a;const X=Year.newHolocene(0),tt=Year.newHolocene(32767);export class Month extends Q{static get min(){return et}static get max(){return nt}toString(){return O(this._d,this._pos).toString()}toIsoString(){return this._month_iso(this._pos)}toJSON(){return O(this._d,this._pos)}valueOf(){return O(this._d,this._pos)}serialize(t){t.mustPushNumberBE(this._d.getUint8(this._pos),4)}get serialSizeBits(){return 4}validate(){return i("month",O(this._d,this._pos)).atMost(12).throwNot(),this}get[Symbol.toStringTag](){return"Month"}[s](){return`Month(${O(this._d,this._pos)})`}static new(t){i("month",t).natural().atMost(12).throwNot();const e=new DataView(new ArrayBuffer(1));return A(e,0,t),new Month(e)}static fromDate(t){const e=new DataView(new ArrayBuffer(1));return A(e,0,t.getMonth()+1),new Month(e)}static fromDateUtc(t){const e=new DataView(new ArrayBuffer(1));return A(e,0,t.getUTCMonth()+1),new Month(e)}static parse(t,e=!1){const n=new DataView(new ArrayBuffer(1)),r=t.getReset();if(t.trim(),"now"==t.toString().toLowerCase())t.shrink(3),A(n,0,(new Date).getMonth()+1);else{const i=Q.parseMonth(n,0,t,e,r);if(i)throw i}return new Month(n)}static now(){const t=new DataView(new ArrayBuffer(1));return A(t,0,(new Date).getMonth()+1),new Month(t)}static deserialize(t){const e=new DataView(new ArrayBuffer(1));return e.setUint8(0,t.readNumberBE(4)),new Month(e)}static lastDay(t,e){const n=null!=e&&Year.isLeap(e);return 2==t&&n?29:U[t]}}Month.storageBytes=1,Month.serialBits=4;const et=Month.new(1),nt=Month.new(12);export class Day extends Q{static get min(){return rt}static get max(){return it}toString(){return N(this._d,this._pos).toString()}toIsoString(){return this._day_iso(this._pos)}toJSON(){return N(this._d,this._pos)}valueOf(){return N(this._d,this._pos)}serialize(t){t.mustPushNumberBE(this._d.getUint8(this._pos),5)}get serialSizeBits(){return 5}validate(){return i("day",N(this._d,this._pos)).atMost(31).throwNot(),this}get[Symbol.toStringTag](){return"DayOfMonth"}[s](){return`DayOfMonth(${N(this._d,this._pos)})`}static new(t){i("day",t).natural().atMost(31).throwNot();const e=new DataView(new ArrayBuffer(1));return b(e,0,t),new Day(e)}static fromDate(t){const e=new DataView(new ArrayBuffer(1));return b(e,0,t.getDate()),new Day(e)}static fromDateUtc(t){const e=new DataView(new ArrayBuffer(1));return b(e,0,t.getUTCDate()),new Day(e)}static parse(t,e=!1){const n=new DataView(new ArrayBuffer(1)),r=t.getReset();if(t.trim(),"now"==t.toString().toLowerCase())t.shrink(3),b(n,0,(new Date).getDate());else{const i=Q.parseDay(n,0,t,e,r);if(i)throw i}return new Day(n)}static now(){const t=new DataView(new ArrayBuffer(1));return b(t,0,(new Date).getDate()),new Day(t)}static deserialize(t){const e=new DataView(new ArrayBuffer(1));return e.setUint8(0,t.readNumberBE(5)),new Day(e)}}Day.storageBytes=1,Day.serialBits=5;const rt=Day.new(1),it=Day.new(31);export class DateOnly extends Q{static get min(){return st}static get max(){return ot}get year(){return S(this._d,this._pos+2)}get month(){return O(this._d,this._pos+1)}get day(){return N(this._d,this._pos)}toString(t="-"){return this._date_iso(this._pos,t)}toJSON(){return this.valueOf()}toDate(){const[t,e,n]=k(this._d,this._pos);return new Date(t,e-1,n)}toUnixDays(){return super.toUnixDays(this._pos)}toUnixTime(){return super.toUnixDays(this._pos)*f}toUnixTimeMs(){return super.toUnixDays(this._pos)*l}valueOf(){const[t,e,n]=k(this._d,this._pos);return t<0?1e4*t-100*e-n:1e4*t+100*e+n}serialize(t){E(this._d,this._pos,t)}get serialSizeBits(){return 24}validate(){return this._date_valid(this._pos),this}get[Symbol.toStringTag](){return"DateOnly"}[s](){return`DateOnly(${this._date_iso(this._pos,"-")})`}addSafe(t){const e=new DataView(new ArrayBuffer(4));return Q.dateFromUnixDays(e,0,super.toUnixDays(this._pos)+(0|t)),new DateOnly(e)}add(t,e=0){let n=0;t&&(n+=12*(0|t)),e&&(n+=0|e);const r=n/12|0;n%=12;let[i,s,o]=k(this._d,this._pos);i+=r,s+=n;const a=Month.lastDay(s,i);o>a&&(o=a);const u=new DataView(new ArrayBuffer(4));return v(u,0,i,s,o),new DateOnly(u)}static new(t,e,n){const r=new DataView(new ArrayBuffer(4));return Q.vetDate(t,e,n),v(r,0,t,e,n),new DateOnly(r)}static fromValue(t){const e=new DataView(new ArrayBuffer(4));return Q.dateFromValue(e,0,t),new DateOnly(e)}static fromUnixDays(t){const e=new DataView(new ArrayBuffer(4));return Q.dateFromUnixDays(e,0,t),new DateOnly(e)}static fromDate(t){const e=t.valueOf()-t.getTimezoneOffset()*g,n=new DataView(new ArrayBuffer(4));return Q.dateFromUnixDays(n,0,e/l),new DateOnly(n)}static fromDateUtc(t){const e=new DataView(new ArrayBuffer(4));return Q.dateFromUnixDays(e,0,t.valueOf()/l),new DateOnly(e)}static fromUnixTime(t){const e=new DataView(new ArrayBuffer(4));return Q.dateFromUnixDays(e,0,t/f),new DateOnly(e)}static fromUnixTimeMs(t){const e=new DataView(new ArrayBuffer(4));return Q.dateFromUnixDays(e,0,t/l),new DateOnly(e)}static parse(t,e=!1){const n=new DataView(new ArrayBuffer(4)),r=t.getReset();if(t.trim(),"now"==t.toString().toLowerCase()){t.shrink(3);const e=new Date;v(n,0,e.getFullYear(),e.getMonth()+1,e.getDate())}else{const i=Q.parseDate(n,0,t,e,r);if(i)throw i}return new DateOnly(n)}static now(){const t=new Date,e=t.valueOf()-t.getTimezoneOffset()*g,n=new DataView(new ArrayBuffer(4));return Q.dateFromUnixDays(n,0,e/l),new DateOnly(n)}static nowUtc(){const t=(new Date).valueOf(),e=new DataView(new ArrayBuffer(4));return Q.dateFromUnixDays(e,0,t/l),new DateOnly(e)}static deserialize(t){const e=new DataView(new ArrayBuffer(4));return z(e,0,t),new DateOnly(e)}static dayOfWeek(t){return t>=-4?(t+4)%7:(t+5)%7+6}}DateOnly.storageBytes=4,DateOnly.serialBits=24;const st=DateOnly.new(c,1,1),ot=DateOnly.new(h,12,31);export class Hour extends Q{static get min(){return at}static get max(){return ut}toString(){return L(this._d,this._pos).toString()}toIsoString(){return this._hour_iso(this._pos)}toJSON(){return L(this._d,this._pos)}valueOf(){return L(this._d,this._pos)}serialize(t){t.mustPushNumberBE(this._d.getUint8(this._pos),5)}get serialSizeBits(){return 5}validate(){return i("hour",L(this._d,this._pos)).lt(24).throwNot(),this}get[Symbol.toStringTag](){return"HourOfDay"}[s](){return`HourOfDay(${L(this._d,this._pos)})`}static new(t){i("hour",t).unsigned().lt(24).throwNot();const e=new DataView(new ArrayBuffer(1));return F(e,0,t),new Hour(e)}static fromDate(t){const e=new DataView(new ArrayBuffer(1));return F(e,0,t.getHours()),new Hour(e)}static fromDateUtc(t){const e=new DataView(new ArrayBuffer(1));return F(e,0,t.getUTCHours()),new Hour(e)}static fromUnixTime(t){const e=new DataView(new ArrayBuffer(1));return F(e,0,t%f/m),new Hour(e)}static fromUnixTimeMs(t){const e=new DataView(new ArrayBuffer(1));return F(e,0,t%l/d),new Hour(e)}static fromUnixTimeUs(t){const e=new DataView(new ArrayBuffer(1));return F(e,0,t%p/D),new Hour(e)}static parse(t,e=!1){const n=new DataView(new ArrayBuffer(1)),r=t.getReset();if(t.trim(),"now"==t.toString().toLowerCase())t.shrink(3),F(n,0,(new Date).getHours());else{const i=Q.parseHour(n,0,t,e,r);if(i)throw i}return new Hour(n)}static now(){const t=new DataView(new ArrayBuffer(1));return F(t,0,(new Date).getHours()),new Hour(t)}static nowUtc(){const t=new DataView(new ArrayBuffer(1));return F(t,0,(new Date).getUTCHours()),new Hour(t)}static deserialize(t){const e=new DataView(new ArrayBuffer(1));return F(e,0,t.readNumberBE(5)),new Hour(e)}}Hour.storageBytes=1,Hour.serialBits=5;const at=Hour.new(0),ut=Hour.new(23);export class Minute extends Q{static get min(){return wt}static get max(){return ct}toString(){return H(this._d,this._pos).toString()}toIsoString(){return this._minute_iso(this._pos)}toJSON(){return H(this._d,this._pos)}valueOf(){return H(this._d,this._pos)}serialize(t){t.mustPushNumberBE(H(this._d,this._pos),6)}get serialSizeBits(){return 6}validate(){return i("minute",H(this._d,this._pos)).lt(60).throwNot(),this}get[Symbol.toStringTag](){return"Minute"}[s](){return`Minute(${H(this._d,this._pos)})`}static new(t){i("minute",t).unsigned().lt(60).throwNot();const e=new DataView(new ArrayBuffer(1));return Y(e,0,t),new Minute(e)}static fromDate(t){const e=new DataView(new ArrayBuffer(1));return Y(e,0,t.getMinutes()),new Minute(e)}static fromDateUtc(t){const e=new DataView(new ArrayBuffer(1));return Y(e,0,t.getUTCMinutes()),new Minute(e)}static fromUnixTime(t){const e=new DataView(new ArrayBuffer(1));return Y(e,0,t%m/60),new Minute(e)}static fromUnixTimeMs(t){const e=new DataView(new ArrayBuffer(1));return Y(e,0,t%d/g),new Minute(e)}static fromUnixTimeUs(t){const e=new DataView(new ArrayBuffer(1));return Y(e,0,t%D/y),new Minute(e)}static parse(t,e=!1){const n=new DataView(new ArrayBuffer(1)),r=t.getReset();if(t.trim(),"now"==t.toString().toLowerCase())t.shrink(3),Y(n,0,(new Date).getMinutes());else{const i=Q.parseMinute(n,0,t,e,r);if(i)throw i}return new Minute(n)}static now(){const t=new DataView(new ArrayBuffer(1));return Y(t,0,(new Date).getMinutes()),new Minute(t)}static nowUtc(){const t=new DataView(new ArrayBuffer(1));return Y(t,0,(new Date).getUTCMinutes()),new Minute(t)}static deserialize(t){const e=new DataView(new ArrayBuffer(1));return Y(e,0,t.readNumberBE(6)),new Minute(e)}}Minute.storageBytes=1,Minute.serialBits=6;const wt=Minute.new(0),ct=Minute.new(59);export class Second extends Q{static get min(){return ht}static get max(){return ft}toString(){return $(this._d,this._pos).toString()}toIsoString(){return this._second_iso(this._pos)}toJSON(){return $(this._d,this._pos)}valueOf(){return $(this._d,this._pos)}serialize(t){t.mustPushNumberBE($(this._d,this._pos),6)}get serialSizeBits(){return 6}validate(){return i("second",$(this._d,this._pos)).lt(60).throwNot(),this}get[Symbol.toStringTag](){return"Second"}[s](){return`Second(${$(this._d,this._pos)})`}static new(t){i("second",t).unsigned().lt(60).throwNot();const e=new DataView(new ArrayBuffer(1));return C(e,0,t),new Second(e)}static fromDate(t){const e=new DataView(new ArrayBuffer(1));return C(e,0,t.getSeconds()),new Second(e)}static fromUnixTime(t){const e=new DataView(new ArrayBuffer(1));return C(e,0,t%60),new Second(e)}static fromUnixTimeMs(t){const e=new DataView(new ArrayBuffer(1));return C(e,0,t%g/_),new Second(e)}static fromUnixTimeUs(t){const e=new DataView(new ArrayBuffer(1));return C(e,0,t%y/B),new Second(e)}static parse(t,e=!1){const n=new DataView(new ArrayBuffer(1)),r=t.getReset();if(t.trim(),"now"==t.toString().toLowerCase()){t.shrink(3);C(n,0,(performance.timeOrigin+performance.now())/_%60)}else{const i=Q.parseSecond(n,0,t,e,r);if(i)throw i}return new Second(n)}static now(){const t=new DataView(new ArrayBuffer(1));return C(t,0,(new Date).getSeconds()),new Second(t)}static deserialize(t){const e=new DataView(new ArrayBuffer(1));return C(e,0,t.readNumberBE(6)),new Second(e)}}Second.storageBytes=1,Second.serialBits=6;const ht=Second.new(0),ft=Second.new(59);export class Millisecond extends Q{static get min(){return mt}static get max(){return lt}valueOf(){return P(this._d,this._pos)}toString(){return P(this._d,this._pos).toString()}toIsoString(){return this._milli_iso(this._pos)}toJSON(){return P(this._d,this._pos)}serialize(t){t.mustPushNumberBE(P(this._d,this._pos),u)}get serialSizeBits(){return u}validate(){return i("millisecond",P(this._d,this._pos)).lt(1e3).throwNot(),this}get[Symbol.toStringTag](){return"Millisecond"}[s](){return`Millisecond(${P(this._d,this._pos)})`}static new(t){i("millisecond",t).unsigned().lt(1e3).throwNot();const e=new DataView(new ArrayBuffer(2));return J(e,0,t),new Millisecond(e)}static fromDate(t){const e=new DataView(new ArrayBuffer(2));return J(e,0,t.getMilliseconds()),new Millisecond(e)}static fromUnixTime(t){const e=new DataView(new ArrayBuffer(2));return J(e,0,t*_%_),new Millisecond(e)}static fromUnixTimeMs(t){const e=new DataView(new ArrayBuffer(2));return J(e,0,t%_),new Millisecond(e)}static fromUnixTimeUs(t){const e=new DataView(new ArrayBuffer(2));return J(e,0,t/1e3%_),new Millisecond(e)}static parse(t,e=!1,n=!1){const r=new DataView(new ArrayBuffer(2)),i=t.getReset();if(t.trim(),"now"==t.toString().toLowerCase()){t.shrink(3);J(r,0,(performance.timeOrigin+performance.now())%_)}else{const s=Q.parseMilli(r,0,t,e,n,i);if(s)throw s}return new Millisecond(r)}static now(){const t=performance.timeOrigin+performance.now(),e=new DataView(new ArrayBuffer(2));return J(e,0,t%_),new Millisecond(e)}static deserialize(t){const e=new DataView(new ArrayBuffer(2));return J(e,0,t.readNumberBE(u)),new Millisecond(e)}}Millisecond.storageBytes=2,Millisecond.serialBits=u;const mt=Millisecond.new(0),lt=Millisecond.new(999);export class Microsecond extends Q{static get min(){return dt}static get max(){return gt}valueOf(){return R(this._d,this._pos)}toString(){return R(this._d,this._pos).toString()}toIsoString(){return this._micro_iso(this._pos)}toJSON(){return R(this._d,this._pos)}serialize(t){t.mustPushNumberBE(R(this._d,this._pos),w)}get serialSizeBits(){return w}validate(){return i("microsecond",R(this._d,this._pos)).lt(B).throwNot(),this}get[Symbol.toStringTag](){return"Microsecond"}[s](){return`Microsecond(${R(this._d,this._pos)})`}static new(t){i("microsecond",t).unsigned().lt(B).throwNot();const e=new DataView(new ArrayBuffer(3));return I(e,0,t),new Microsecond(e)}static fromDate(t){const e=new DataView(new ArrayBuffer(3));return I(e,0,1e3*t.getMilliseconds()),new Microsecond(e)}static fromUnixTime(t){const e=new DataView(new ArrayBuffer(3));return I(e,0,t*B%B),new Microsecond(e)}static fromUnixTimeMs(t){const e=new DataView(new ArrayBuffer(3));return I(e,0,t%_*1e3),new Microsecond(e)}static fromUnixTimeUs(t){const e=new DataView(new ArrayBuffer(3));return I(e,0,t%B),new Microsecond(e)}static parse(t,e=!1,n=!1){const r=new DataView(new ArrayBuffer(3)),i=t.getReset();if(t.trim(),"now"==t.toString().toLowerCase()){t.shrink(3);I(r,0,(performance.timeOrigin+performance.now())%B)}else{const s=Q.parseMicro(r,0,t,e,n,i);if(s)throw s}return new Microsecond(r)}static now(){const t=performance.timeOrigin+performance.now(),e=new DataView(new ArrayBuffer(3));return I(e,0,1e3*t%B),new Microsecond(e)}static deserialize(t){const e=new DataView(new ArrayBuffer(3));return I(e,0,t.readNumberBE(w)),new Microsecond(e)}}Microsecond.storageBytes=3,Microsecond.serialBits=w;const dt=Microsecond.new(0),gt=Microsecond.new(999999);export class TimeOnly extends Q{static get min(){return _t}static get max(){return pt}get hour(){return L(this._d,this._pos+5)}get minute(){return H(this._d,this._pos+4)}get second(){return $(this._d,this._pos+3)}get microsecond(){return R(this._d,this._pos)}toString(t=!0){return super._time_iso(this._pos,t)}toJSON(){return super._time_iso(this._pos,!0)}toMicroseconds(){return super.timeToUs(this._pos)}toMilliseconds(){return super.timeToUs(this._pos)/1e3}toSeconds(){return super.timeToUs(this._pos)/B}valueOf(){const[t,e,n,r]=Z(this._d,this._pos);return 1e10*t+1e8*e+1e6*n+r}serialize(t){W(this._d,this._pos,t)}get serialSizeBits(){return 37}validate(){return this._time_valid(this._pos),this}get[Symbol.toStringTag](){return"TimeOnly"}[s](){return`TimeOnly(${this._time_iso(this._pos,!0)})`}static new(t,e,n,r){Q.vetTime(t,e,n,r);const i=new DataView(new ArrayBuffer(6));return G(i,0,t,e,n,r),new TimeOnly(i)}static fromValue(t){const e=new DataView(new ArrayBuffer(6));return Q.timeFromValue(e,0,t),new TimeOnly(e)}static fromUnixTimeUs(t){const e=new DataView(new ArrayBuffer(6));return G(e,0,t%p/D,t%D/y,t%y/B,t%B),new TimeOnly(e)}static fromUnixTimeMs(t){const e=new DataView(new ArrayBuffer(6));return G(e,0,t%l/d,t%d/g,t%g/_,1e3*t%B),new TimeOnly(e)}static fromUnixTime(t){const e=new DataView(new ArrayBuffer(6));return G(e,0,t%f/m,t%m/60,t%60,t*B%B),new TimeOnly(e)}static fromDate(t){const e=t.valueOf()-t.getTimezoneOffset()*g,n=new DataView(new ArrayBuffer(6));return G(n,0,e%l/d,e%d/g,e%g/_,1e3*e%B),new TimeOnly(n)}static parse(t,e=!1){const n=new DataView(new ArrayBuffer(6)),r=t.getReset();if(t.trim(),"now"==t.toString().toLowerCase()){t.shrink(3);let e=performance.timeOrigin+performance.now();e-=new Date(e).getTimezoneOffset()*g,G(n,0,e%l/d,e%d/g,e%g/_,1e3*e%B)}else{const i=Q.parseTime(n,0,t,e,r);if(i)throw i}return new TimeOnly(n)}static now(){let t=performance.timeOrigin+performance.now();t-=new Date(t).getTimezoneOffset()*g;const e=new DataView(new ArrayBuffer(6));return G(e,0,t%l/d,t%d/g,t%g/_,1e3*t%B),new TimeOnly(e)}static deserialize(t){const e=new DataView(new ArrayBuffer(6));return K(e,0,t),new TimeOnly(e)}}TimeOnly.storageBytes=6,TimeOnly.serialBits=37;const _t=TimeOnly.new(0,0,0,0),pt=TimeOnly.new(23,59,59,999999);export class TimeOnlyMs extends Q{static get min(){return Dt}static get max(){return yt}get hour(){return L(this._d,this._pos+4)}get minute(){return H(this._d,this._pos+3)}get second(){return $(this._d,this._pos+2)}get millisecond(){return P(this._d,this._pos)}toString(t=!0){let e="",n="";return t&&(e=":",n="."),this._hour_iso(this._pos+4)+e+this._minute_iso(this._pos+3)+e+this._second_iso(this._pos+2)+n+this._milli_iso(this._pos)}toJSON(){return this.toString(!0)}toMicroseconds(){const[t,e,n,r]=j(this._d,this._pos);return t*D+e*y+n*B+1e3*r}toMilliseconds(){const[t,e,n,r]=j(this._d,this._pos);return t*d+e*g+n*_+r}toSeconds(){const[t,e,n,r]=j(this._d,this._pos);return t*m+60*e+n+r/1e3}valueOf(){const[t,e,n,r]=j(this._d,this._pos);return 1e7*t+1e5*e+1e3*n+r}serialize(t){t.mustPushNumberBE(P(this._d,this._pos),u),t.mustPushNumberBE($(this._d,this._pos+2),6),t.mustPushNumberBE(H(this._d,this._pos+3),6),t.mustPushNumberBE(L(this._d,this._pos+4),5)}get serialSizeBits(){return 27}validate(){const[t,e,n,r]=j(this._d,this._pos);return i("hour",t).lt(24).throwNot(),i("minute",e).lt(60).throwNot(),i("second",n).lt(60).throwNot(),i("millisecond",r).lt(1e3).throwNot(),this}get[Symbol.toStringTag](){return"TimeOnlyMs"}[s](){return`TimeOnlyMs(${this.toString()})`}static new(t,e,n,r){i("hour",t).unsigned().lt(24).throwNot(),i("minute",e).unsigned().lt(60).throwNot(),i("second",n).unsigned().lt(60).throwNot(),i("millisecond",r).unsigned().lt(1e3).throwNot();const s=new DataView(new ArrayBuffer(5));return q(s,0,t,e,n,r),new TimeOnlyMs(s)}static fromValue(t){const e=t%1e3,n=(t=(t-e)/1e3)%100,r=(t=(t-n)/100)%100;i("hour",t=(t-r)/100).unsigned().lt(24).throwNot(),i("minute",r).unsigned().lt(60).throwNot(),i("second",n).unsigned().lt(60).throwNot(),i("millisecond",e).unsigned().lt(1e3).throwNot();const s=new DataView(new ArrayBuffer(5));return q(s,0,t,r,n,e),new TimeOnlyMs(s)}static fromUnixTimeUs(t){const e=new DataView(new ArrayBuffer(5));return q(e,0,t%p/D,t%D/y,t%y/B,t/1e3%1e3),new TimeOnlyMs(e)}static fromUnixTimeMs(t){const e=new DataView(new ArrayBuffer(5));return q(e,0,t%l/d,t%d/g,t%g/_,t%_),new TimeOnlyMs(e)}static fromUnixTime(t){const e=new DataView(new ArrayBuffer(5));return q(e,0,t%f/m,t%m/60,t%60,1e3*t%1e3),new TimeOnlyMs(e)}static fromDate(t){const e=t.valueOf()-t.getTimezoneOffset()*g,n=new DataView(new ArrayBuffer(5));return q(n,0,e%l/d,e%d/g,e%g/_,e%_),new TimeOnlyMs(n)}static parse(e,n=!1){const r=new DataView(new ArrayBuffer(5)),i=e.getReset();if(e.trim(),"now"==e.toString().toLowerCase())return e.shrink(3),TimeOnlyMs.now();let s;if(e.test(/^\d{9}$/)){if(s=Q.parseHour(r,4,e.left(2),n,i),s)throw s;if(e.shrink(2),s=Q.parseMinute(r,3,e.left(2),n,i),s)throw s;if(e.shrink(2),s=Q.parseSecond(r,2,e.left(2),n,i),s)throw s;return e.shrink(2),s=Q.parseMilli(r,0,e,n,!1,i),e.shrink(e.length),new TimeOnlyMs(r)}const o=e.indexOf(":");let a=e.indexOf(":",o+1);const u=e.indexOf(".",a+1)-a-1;if(a=a-o-1,o>0&&a>0&&u>0){if(s=Q.parseHour(r,4,e.left(o),n,i),s)throw s;if(e.shrink(o+1),s=Q.parseMinute(r,3,e.left(a).trim(),n,i),s)throw s;if(e.shrink(a+1),s=Q.parseSecond(r,2,e.left(u).trim(),n,i),s)throw s;if(e.shrink(u+1),s=Q.parseMilli(r,0,e.trim(),n,!0,i),s)throw s;return e.shrink(e.length),new TimeOnlyMs(r)}throw new t("Expecting hh:mm:ss.###, or hhmmss###","time",e)}static now(){let t=performance.timeOrigin+performance.now();const e=new Date(t),n=new DataView(new ArrayBuffer(5));return t-=e.getTimezoneOffset()*g,q(n,0,t%l/d,t%d/g,t%g/_,t%_),new TimeOnlyMs(n)}static deserialize(t){const e=new DataView(new ArrayBuffer(5));return J(e,0,t.readNumberBE(u)),e.setUint8(2,t.readNumberBE(6)),e.setUint8(3,t.readNumberBE(6)),e.setUint8(4,t.readNumberBE(5)),new TimeOnlyMs(e)}}TimeOnlyMs.storageBytes=5,TimeOnlyMs.serialBits=27;const Dt=TimeOnlyMs.new(0,0,0,0),yt=TimeOnlyMs.new(23,59,59,999);class Bt extends Q{get year(){return S(this._d,this._pos+6+2)}get month(){return O(this._d,this._pos+6+1)}get day(){return N(this._d,this._pos+6)}get hour(){return L(this._d,this._pos+0+5)}get minute(){return H(this._d,this._pos+0+4)}get second(){return $(this._d,this._pos+0+3)}get microsecond(){return R(this._d,this._pos+0)}toString(t="T"){return this._date_iso(this._pos+6,"-")+t+this._time_iso(this._pos+0,!0)}toJSON(){return this._date_iso(this._pos+6,"-")+"T"+this._time_iso(this._pos+0,!0)}toUnixTime(){return super.toUnixDays(this._pos+6)*f+super.timeToUs(this._pos+0)/B}toUnixTimeMs(){return super.toUnixDays(this._pos+6)*l+super.timeToUs(this._pos+0)/1e3}serialize(t){E(this._d,this._pos+6,t),W(this._d,this._pos+0,t)}get serialSizeBits(){return 61}_addDe(t,e){let n=super.timeToUs(this._pos+0)%D,r=24*super.toUnixDays(this._pos+6)+this.hour;const[i,s]=t.toDhMiso();r+=i,n+=s,n>=D&&(r+=1,n-=D);const o=n+r%24*D;G(e,0,o%p/D,o%D/y,o%y/B,o%B),Q.dateFromUnixDays(e,6,r/24|0)}_addDv(t,e){let n=super.timeToUs(this._pos+0)%D,[r,i,s]=k(this._d,this._pos+6);const[o,a,u,w]=t.toYMDhMiso();r+=o,i+=a,i>12&&(r+=1,i-=12);let c=Month.lastDay(0|i,r);s>c&&(s=c),s+=c*(i%1)|0,i|=0;let h=24*s+L(this._d,this._pos+0+5);for(h+=u,n+=w,n>=D&&(h+=1,n-=D);h>=24*c+23;)i+=1,i>12&&(r+=1,i=1),h-=24*c,c=Month.lastDay(i,r);const f=n+h%24*D;G(e,0,f%p/D,f%D/y,f%y/B,f%B),v(e,6,r,i,h/24|0)}_subDe(t,e){const n=super.timeToUs(this._pos+0);let r=n%D,i=n/D|0;i+=24*super.toUnixDays(this._pos+6);const[s,o]=t.toDhMiso();i-=s,r-=o,r<0&&(i-=1,r+=D);const a=r+i%24*D;G(e,0,a%p/D,a%D/y,a%y/B,a%B),Q.dateFromUnixDays(e,6,i/24|0)}_subDv(t,e){const n=super.timeToUs(this._pos+0);let r=n%D,i=n/D|0,[s,o,a]=k(this._d,this._pos+6);const[u,w,c,h]=t.toYMDhMiso();s-=u,o-=w;let f=o%1;o=Math.ceil(o),o<1&&(s-=1,o+=12,f=0-f);let m=Month.lastDay(o,s);for(a>m&&(a=m),f>0&&(a-=m*(1-f)|0),i+=24*(a-1),i-=c,r-=h,r<0&&(i-=1,r+=D);i<0;)o-=1,o<1&&(s-=1,o=12),m=Month.lastDay(o,s),i+=24*m;const l=r+i%24*D;G(e,0,l%p/D,l%D/y,l%y/B,l%B),v(e,6,s,o,1+i/24|0)}cmp(t,e,n,r){const i=this._d.getUint16(this._pos+8,x),s=t._d.getUint16(t._pos+8,x);if(i>s)return e;if(i<s)return n;let o=this._d.getUint32(this._pos+4,x),a=t._d.getUint32(t._pos+4,x);return o>a?e:o<a?n:(o=this._d.getUint32(this._pos,x),a=t._d.getUint32(t._pos,x),o>a?e:o<a?n:r)}static _diff(t,e){let[r,i,s]=k(t._d,t._pos+6);const[o,a,u]=k(e._d,e._pos+6);r-=o,i-=a,s-=u;let[w,c,h,f]=Z(t._d,t._pos+0);const[m,l,d,g]=Z(e._d,e._pos+0);return w-=m,c-=l,h-=d,f-=g,f<0&&(f+=B,h-=1),h<0&&(h+=60,c-=1),c<0&&(c+=60,w-=1),w<0&&(w+=24,s-=1),s<0&&(s+=Month.lastDay(a,o),i-=1),i<0&&(i+=12,r-=1),n.new({y:r,m:i,d:s,h:w,i:c,s:h,us:f})}static _diffExact(t,e){let n=t.toUnixDays(t._pos+6)-e.toUnixDays(e._pos+6),[i,s,o,a]=Z(t._d,t._pos+0);const[u,w,c,h]=Z(e._d,e._pos+0);return i-=u,s-=w,o-=c,a-=h,a<0&&(a+=B,o-=1),o<0&&(o+=60,s-=1),s<0&&(s+=60,i-=1),i<0&&(i+=24,n-=1),r.new({d:n,h:i,i:s,s:o,us:a})}diff(t){return t.cmp(this,!0,!1,!1)?Bt._diff(t,this):Bt._diff(this,t)}diffExact(t){return t.cmp(this,!0,!1,!1)?Bt._diffExact(t,this):Bt._diffExact(this,t)}}Bt.storageBytes=o,Bt.serialBits=61;export class DateTimeLocal extends Bt{static get min(){return Ut}static get max(){return Mt}toDate(){const[t,e,n]=k(this._d,this._pos+6),[r,i,s,o]=Z(this._d,this._pos+0);return new Date(t,e-1,n,r,i,s,o/1e3)}valueOf(){return this._date_iso(this._pos+6,"")+this._time_iso(this._pos+0,!1)}validate(){return this._time_valid(this._pos+0),this._date_valid(this._pos+6),this}get[Symbol.toStringTag](){return"DateTimeLocal"}[s](){return`DateTimeLocal(${this.toString()})`}add(t){const e=new DataView(new ArrayBuffer(o));return t instanceof r?this._addDe(t,e):this._addDv(t,e),new DateTimeLocal(e)}sub(t){const e=new DataView(new ArrayBuffer(o));return t instanceof r?this._subDe(t,e):this._subDv(t,e),new DateTimeLocal(e)}diff(t){return super.diff(t)}diffExact(t){return super.diffExact(t)}gt(t){return super.cmp(t,!0,!1,!1)}gte(t){return super.cmp(t,!0,!1,!0)}lt(t){return super.cmp(t,!1,!0,!1)}lte(t){return super.cmp(t,!1,!0,!0)}eq(t){return super.cmp(t,!1,!1,!0)}neq(t){return super.cmp(t,!0,!0,!1)}static new(t,e,n,r,i,s,a){Q.vetDate(t,e,n),Q.vetTime(r,i,s,a);const u=new DataView(new ArrayBuffer(o));return G(u,0,r,i,s,a),v(u,6,t,e,n),new DateTimeLocal(u)}static fromValue(t){const n=e(t.substring(0,t.length-12)),r=e(t.substring(t.length-12)),i=new DataView(new ArrayBuffer(o));return Q.timeFromValue(i,0,r),Q.dateFromValue(i,6,n),new DateTimeLocal(i)}static fromDate(t){const e=t.valueOf()-t.getTimezoneOffset()*g;return DateTimeLocal.fromUnixTimeMs(e)}static fromUnixTimeMs(t){const e=new DataView(new ArrayBuffer(o));return G(e,0,t%l/d,t%d/g,t%g/_,1e3*t%B),Q.dateFromUnixDays(e,6,t/l),new DateTimeLocal(e)}static fromUnixTime(t){const e=new DataView(new ArrayBuffer(o));return G(e,0,t%f/m,t%m/60,t%60,t*B%B),Q.dateFromUnixDays(e,6,t/f),new DateTimeLocal(e)}static now(){let t=performance.timeOrigin+performance.now();t-=new Date(t).getTimezoneOffset()*g;const e=new DataView(new ArrayBuffer(o));return G(e,0,t%l/d,t%d/g,t%g/_,1e3*t%B),Q.dateFromUnixDays(e,6,t/l),new DateTimeLocal(e)}static parse(e,n=!1){const r=e.getReset();if(e.trim(),"now"==e.toString().toLowerCase())return e.shrink(3),DateTimeLocal.now();const i=new DataView(new ArrayBuffer(o));let s;if(e.test(/^[-+]?\d{20,21}$/)){if(s=Q.parseDateUndelim(i,6,e.left(e.length-12),n,r),s)throw s;if(e.shrink(e.length-12),s=Q.parseTimeUndelim(i,0,e,n,r),s)throw s;return e.shrink(e.length),new DateTimeLocal(i)}const a=e.indexOfAny(["t","T"]);if(a>0){if(s=Q.parseDate(i,6,e.left(a),n,r),s)throw s;if(e.shrink(a+1),s=Q.parseTime(i,0,e,n,r),s)throw s;return e.shrink(e.length),new DateTimeLocal(i)}throw new t("Expecting yyyy-mm-ddThh:mm:ss.uuuuuuZ or a 20-21 digit date with optional sign/trailing z","datetime",e)}static deserialize(t){const e=new DataView(new ArrayBuffer(o));return z(e,6,t),K(e,0,t),new DateTimeLocal(e)}}const Ut=DateTimeLocal.new(c,1,1,0,0,0,0),Mt=DateTimeLocal.new(h,12,31,23,59,59,999999);export class DateTimeUtc extends Bt{static get min(){return Tt}static get max(){return xt}toString(t="T"){return this._date_iso(this._pos+6,"-")+t+this._time_iso(this._pos+0,!0)+"Z"}toDate(){return new Date(super.toUnixDays(this._pos+6)*l+this.timeToUs(this._pos+0)/1e3)}valueOf(){return this._date_iso(this._pos+6,"")+this._time_iso(this._pos+0,!1)}validate(){return this._time_valid(this._pos+0),this._date_valid(this._pos+6),this}get[Symbol.toStringTag](){return"DateTimeUtc"}[s](){return`DateTimeUtc(${this.toString()})`}add(t){const e=new DataView(new ArrayBuffer(o));return t instanceof r?this._addDe(t,e):this._addDv(t,e),new DateTimeUtc(e)}sub(t){const e=new DataView(new ArrayBuffer(o));return t instanceof r?this._subDe(t,e):this._subDv(t,e),new DateTimeUtc(e)}gt(t){return super.cmp(t,!0,!1,!1)}gte(t){return super.cmp(t,!0,!1,!0)}lt(t){return super.cmp(t,!1,!0,!1)}lte(t){return super.cmp(t,!1,!0,!0)}eq(t){return super.cmp(t,!1,!1,!0)}neq(t){return super.cmp(t,!0,!0,!1)}diff(t){return super.diff(t)}diffExact(t){return super.diffExact(t)}static new(t,e,n,r,i,s,a){Q.vetDate(t,e,n),Q.vetTime(r,i,s,a);const u=new DataView(new ArrayBuffer(o));return G(u,0,r,i,s,a),v(u,6,t,e,n),new DateTimeUtc(u)}static fromValue(t){const n=e(t.substring(0,t.length-12)),r=e(t.substring(t.length-12)),i=new DataView(new ArrayBuffer(o));return Q.timeFromValue(i,0,r),Q.dateFromValue(i,6,n),new DateTimeUtc(i)}static fromDate(t){const e=t.valueOf()-t.getTimezoneOffset()*g,n=new DataView(new ArrayBuffer(o));return G(n,0,e%l/d,e%d/g,e%g/_,1e3*e%B),Q.dateFromUnixDays(n,6,e/l),new DateTimeUtc(n)}static fromUnixTimeMs(t){const e=new DataView(new ArrayBuffer(o));return G(e,0,t%l/d,t%d/g,t%g/_,1e3*t%B),Q.dateFromUnixDays(e,6,t/l),new DateTimeUtc(e)}static fromUnixTime(t){const e=new DataView(new ArrayBuffer(o));return G(e,0,t%f/m,t%m/60,t%60,t*B%B),Q.dateFromUnixDays(e,6,t/f),new DateTimeUtc(e)}static now(){const t=performance.timeOrigin+performance.now(),e=new DataView(new ArrayBuffer(o));return G(e,0,t%l/d,t%d/g,t%g/_,1e3*t%B),Q.dateFromUnixDays(e,6,t/l),new DateTimeUtc(e)}static parse(e,n=!1){const r=e.getReset();if(e.trim(),"now"==e.toString().toLowerCase())return e.shrink(3),DateTimeUtc.now();const i=new DataView(new ArrayBuffer(o));let s;let a=!1;if(e.lastIndexOfAny(["z","Z"])==e.length-1&&(e.shrink(0,1),a=!0),e.test(/^[-+]?\d{20,21}$/)){if(s=Q.parseDateUndelim(i,6,e.left(e.length-12),n,r),s)throw s;if(e.shrink(e.length-12),s=Q.parseTimeUndelim(i,0,e,n,r),s)throw s;return e.shrink(e.length),new DateTimeUtc(i)}const u=e.indexOfAny(["t","T"]);if(u>0&&(a||!n)){if(s=Q.parseDate(i,6,e.left(u),n,r),s)throw s;if(e.shrink(u+1),s=Q.parseTime(i,0,e,n,r),s)throw s;return e.shrink(e.length),new DateTimeUtc(i)}throw r(),new t("Expecting yyyy-mm-ddThh:mm:ss.uuuuuuZ or a 20-21 digit date with optional sign/trailing z","datetime",e)}static deserialize(t){const e=new DataView(new ArrayBuffer(o));return z(e,6,t),K(e,0,t),new DateTimeUtc(e)}}const Tt=DateTimeUtc.new(c,1,1,0,0,0,0),xt=DateTimeUtc.new(h,12,31,23,59,59,999999);