@ma.vu/appdate 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var T=Object.create;var D=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var w=(a,t)=>{for(var e in t)D(a,e,{get:t[e],enumerable:!0})},c=(a,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of j(t))!S.call(a,o)&&o!==e&&D(a,o,{get:()=>t[o],enumerable:!(i=L(t,o))||i.enumerable});return a};var s=(a,t,e)=>(e=a!=null?T(M(a)):{},c(t||!a||!a.__esModule?D(e,"default",{value:a,enumerable:!0}):e,a)),Y=a=>c(D({},"__esModule",{value:!0}),a);var U={};w(U,{AppDate:()=>d,formatLocalTime:()=>k,getLocalizedDateString:()=>z,isDateString:()=>h,setAppDateLanguage:()=>O,setTimezone:()=>A});module.exports=Y(U);var r=s(require("dayjs"),1),F=require("dayjs/locale/de"),
|
|
2
|
+
"use strict";var T=Object.create;var D=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var w=(a,t)=>{for(var e in t)D(a,e,{get:t[e],enumerable:!0})},c=(a,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of j(t))!S.call(a,o)&&o!==e&&D(a,o,{get:()=>t[o],enumerable:!(i=L(t,o))||i.enumerable});return a};var s=(a,t,e)=>(e=a!=null?T(M(a)):{},c(t||!a||!a.__esModule?D(e,"default",{value:a,enumerable:!0}):e,a)),Y=a=>c(D({},"__esModule",{value:!0}),a);var U={};w(U,{AppDate:()=>d,formatLocalTime:()=>k,getLocalizedDateString:()=>z,isDateString:()=>h,setAppDateLanguage:()=>O,setTimezone:()=>A});module.exports=Y(U);var r=s(require("dayjs"),1),F=require("dayjs/locale/de"),l=s(require("dayjs/plugin/customParseFormat.js"),1),p=s(require("dayjs/plugin/isBetween.js"),1),y=s(require("dayjs/plugin/localizedFormat.js"),1),f=s(require("dayjs/plugin/timezone.js"),1),g=s(require("dayjs/plugin/utc.js"),1);r.default.locale("de");r.default.extend(g.default);r.default.extend(f.default);r.default.extend(l.default);r.default.extend(p.default);r.default.extend(y.default);async function O(a){switch(a){case"de":{let t=await import("dayjs/locale/de-ch");r.default.locale(t.default);break}case"fr":{let t=await import("dayjs/locale/fr-ch");r.default.locale(t.default);break}case"en":default:{let t=await import("dayjs/locale/en");r.default.locale(t.default);break}}}var n="Europe/Zurich";function A(a){n=a}var m="HH:mm",u="HH:mm:ssZ",d=class a{timezone;dayjsDate;static INVALID_DATE=(0,r.default)("");constructor(t,e,{invalid:i}={invalid:!1}){if(this.timezone=t,i){this.dayjsDate=a.INVALID_DATE;return}try{if(typeof e=="string"&&!h(e))throw new Error("Invalid Date string, we expect YYYY-DD-MM");this.dayjsDate=r.default.tz(e,t)}catch{console.warn("Could not parse date:",e),this.dayjsDate=a.INVALID_DATE}}static invalid(){return new a(n,"",{invalid:!0})}static now(){return new a(n,(0,r.default)())}static fromDateString(t){return new a(n,t)}static fromLocalTime(t){try{let e=r.default.tz(t,m,n);return new a(n,e)}catch(e){return e instanceof Error&&console.warn(`fromLocalTime(): ${e.message}`),a.invalid()}}static fromUtcString(t){let e=r.default.utc(t);return new a(n,e)}static fromUtcTime(t){let e=r.default.utc(t,u);return new a(n,e)}static minDate(){return a.fromDateString("1900-01-01")}static maxDate(){return a.fromDateString("2200-12-31")}add(t,e){let i=this.dayjsDate.add(t,e);return new a(n,i)}subtract(t,e){let i=this.dayjsDate.subtract(t,e);return new a(n,i)}startOf(t){let e=this.dayjsDate.startOf(t);return new a(n,e)}endOf(t){let e=this.dayjsDate.endOf(t);return new a(n,e)}tomorrow(){return this.add(1,"day")}isValid(){return this.dayjsDate.isValid()}isBefore(t,e){return this.dayjsDate.isBefore(t.dayjsDate,e)}isSame(t,e){return this.dayjsDate.isSame(t.dayjsDate,e)}isToday(){return this.dayjsDate.endOf("d").isSame((0,r.default)().endOf("d"))}isAfter(t,e){return this.dayjsDate.isAfter(t.dayjsDate,e)}isBetween(t=a.minDate(),e=a.maxDate(),i,o){return this.dayjsDate.isBetween(t.dayjsDate,e.dayjsDate,i,o??"[)")}isFirstDayOfWeek(){return this.dayjsDate.day()===1}isWorkingDay(){return x.includes(this.dayjsDate.day())}nextWorkingDay(){let t=this.add(1,"day");return t.isWorkingDay()?t:t.nextWorkingDay()}previousWorkingDay(){let t=this.subtract(1,"day");return t.isWorkingDay()?t:t.previousWorkingDay()}addWorkingDays(t){return t<=0||!Number.isInteger(t)?this:this.nextWorkingDay().addWorkingDays(t-1)}toLocalTime(){return this.format(m)}toUtcTime(){return this.dayjsDate.utc().format(u)}toDateString(){return this.format("YYYY-MM-DD")}toLocalizedDateString({includeDayOfWeek:t=!1}={}){let e=this.dayjsDate.format("L");return t?this.dayjsDate.format("dd, ")+e:e}toUtcDateString(){return this.dayjsDate.utc().format("YYYY-MM-DD")}toUtcString(){return this.dayjsDate.utc().format()}format(t="YYYY-MM-DDTHH:mm:ssZ[Z]"){return this.dayjsDate.format(t)}formatShort({includeDayOfWeek:t=!0}={}){let e=this.format("DD.MM.");return t?this.format("dd, ")+e:e}formatDateTime({includeDayOfWeek:t=!0}={}){let e=this.toLocalizedDateString({includeDayOfWeek:t}),i=this.toLocalTime();return`${e}, ${i}`}},x=[1,2,3,4,5];function z(a,t){return d.fromDateString(a).toLocalizedDateString(t)}function k(a){return d.fromLocalTime(a).toLocalTime()}function h(a){return a?(0,r.default)(a,"YYYY-MM-DD",!0).isValid():!1}0&&(module.exports={AppDate,formatLocalTime,getLocalizedDateString,isDateString,setAppDateLanguage,setTimezone});
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import r from"dayjs";import"dayjs/locale/de";import c from"dayjs/plugin/customParseFormat.js";import m from"dayjs/plugin/isBetween.js";import u from"dayjs/plugin/localizedFormat.js";import
|
|
2
|
+
import r from"dayjs";import"dayjs/locale/de";import c from"dayjs/plugin/customParseFormat.js";import m from"dayjs/plugin/isBetween.js";import u from"dayjs/plugin/localizedFormat.js";import l from"dayjs/plugin/timezone.js";import p from"dayjs/plugin/utc.js";r.locale("de");r.extend(p);r.extend(l);r.extend(c);r.extend(m);r.extend(u);async function w(a){switch(a){case"de":{let t=await import("dayjs/locale/de-ch");r.locale(t.default);break}case"fr":{let t=await import("dayjs/locale/fr-ch");r.locale(t.default);break}case"en":default:{let t=await import("dayjs/locale/en");r.locale(t.default);break}}}var i="Europe/Zurich";function Y(a){i=a}var d="HH:mm",D="HH:mm:ssZ",s=class a{timezone;dayjsDate;static INVALID_DATE=r("");constructor(t,e,{invalid:n}={invalid:!1}){if(this.timezone=t,n){this.dayjsDate=a.INVALID_DATE;return}try{if(typeof e=="string"&&!f(e))throw new Error("Invalid Date string, we expect YYYY-DD-MM");this.dayjsDate=r.tz(e,t)}catch{console.warn("Could not parse date:",e),this.dayjsDate=a.INVALID_DATE}}static invalid(){return new a(i,"",{invalid:!0})}static now(){return new a(i,r())}static fromDateString(t){return new a(i,t)}static fromLocalTime(t){try{let e=r.tz(t,d,i);return new a(i,e)}catch(e){return e instanceof Error&&console.warn(`fromLocalTime(): ${e.message}`),a.invalid()}}static fromUtcString(t){let e=r.utc(t);return new a(i,e)}static fromUtcTime(t){let e=r.utc(t,D);return new a(i,e)}static minDate(){return a.fromDateString("1900-01-01")}static maxDate(){return a.fromDateString("2200-12-31")}add(t,e){let n=this.dayjsDate.add(t,e);return new a(i,n)}subtract(t,e){let n=this.dayjsDate.subtract(t,e);return new a(i,n)}startOf(t){let e=this.dayjsDate.startOf(t);return new a(i,e)}endOf(t){let e=this.dayjsDate.endOf(t);return new a(i,e)}tomorrow(){return this.add(1,"day")}isValid(){return this.dayjsDate.isValid()}isBefore(t,e){return this.dayjsDate.isBefore(t.dayjsDate,e)}isSame(t,e){return this.dayjsDate.isSame(t.dayjsDate,e)}isToday(){return this.dayjsDate.endOf("d").isSame(r().endOf("d"))}isAfter(t,e){return this.dayjsDate.isAfter(t.dayjsDate,e)}isBetween(t=a.minDate(),e=a.maxDate(),n,o){return this.dayjsDate.isBetween(t.dayjsDate,e.dayjsDate,n,o??"[)")}isFirstDayOfWeek(){return this.dayjsDate.day()===1}isWorkingDay(){return y.includes(this.dayjsDate.day())}nextWorkingDay(){let t=this.add(1,"day");return t.isWorkingDay()?t:t.nextWorkingDay()}previousWorkingDay(){let t=this.subtract(1,"day");return t.isWorkingDay()?t:t.previousWorkingDay()}addWorkingDays(t){return t<=0||!Number.isInteger(t)?this:this.nextWorkingDay().addWorkingDays(t-1)}toLocalTime(){return this.format(d)}toUtcTime(){return this.dayjsDate.utc().format(D)}toDateString(){return this.format("YYYY-MM-DD")}toLocalizedDateString({includeDayOfWeek:t=!1}={}){let e=this.dayjsDate.format("L");return t?this.dayjsDate.format("dd, ")+e:e}toUtcDateString(){return this.dayjsDate.utc().format("YYYY-MM-DD")}toUtcString(){return this.dayjsDate.utc().format()}format(t="YYYY-MM-DDTHH:mm:ssZ[Z]"){return this.dayjsDate.format(t)}formatShort({includeDayOfWeek:t=!0}={}){let e=this.format("DD.MM.");return t?this.format("dd, ")+e:e}formatDateTime({includeDayOfWeek:t=!0}={}){let e=this.toLocalizedDateString({includeDayOfWeek:t}),n=this.toLocalTime();return`${e}, ${n}`}},y=[1,2,3,4,5];function O(a,t){return s.fromDateString(a).toLocalizedDateString(t)}function A(a){return s.fromLocalTime(a).toLocalTime()}function f(a){return a?r(a,"YYYY-MM-DD",!0).isValid():!1}export{s as AppDate,A as formatLocalTime,O as getLocalizedDateString,f as isDateString,w as setAppDateLanguage,Y as setTimezone};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.4",
|
|
3
3
|
"name": "@ma.vu/appdate",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "dist/index.js",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
|
+
"publish": "npm run build && npm publish",
|
|
23
24
|
"build": "tsup",
|
|
24
25
|
"test": "bun test"
|
|
25
26
|
},
|