UNPKG

5.07 kBJavaScriptView Raw
1(()=>{"use strict";var e={d:(t,o)=>{for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{FormatDateType:()=>D,formatDate:()=>d,getMonthNames:()=>y,getNumberOfDaysInMonth:()=>L,getTimeOfDay:()=>T,toDate:()=>l,toEpochDay:()=>u,toLocalDate:()=>f,toLocalDateTime:()=>m,toLocalTime:()=>s});const o=require("@js-joda/core"),n=require("@js-joda/locale_en");function a(e){return null!=e&&"object"==typeof e&&void 0!==e._year&&void 0!==e._month&&void 0!==e._day}require("@js-joda/timezone");const r=/^\d{4}-\d{2}-\d{2}$/,i=/(Z|[+-]\d{2}:\d{2})$/,c=/^\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?$/;function f(e,t=o.ZoneId.SYSTEM){if(e instanceof o.LocalDate)return e;if(e instanceof o.LocalDateTime)return e.toLocalDate();if(e instanceof o.ZonedDateTime)return e.toLocalDate();if("number"==typeof e)return o.LocalDate.ofEpochDay(e);if(e instanceof Date)return o.LocalDate.from((0,o.nativeJs)(e,t));if(a(e))return o.LocalDate.of(e._year,e._month,e._day);if("string"==typeof e)return r.test(e)?o.LocalDate.parse(e):i.test(e)?o.ZonedDateTime.parse(e).toLocalDate():o.LocalDateTime.parse(e).toLocalDate();throw new Error("Cannot convert value to LocalDate")}function u(e,t=o.ZoneId.SYSTEM){if("number"==typeof e)return e;if(e instanceof o.LocalDate)return e.toEpochDay();if(e instanceof o.LocalDateTime||e instanceof o.ZonedDateTime||e instanceof Date||a(e)||"string"==typeof e)return f(e,t).toEpochDay();throw new Error("Cannot convert value to epoch integer")}function m(e,t=o.ZoneId.SYSTEM){if(e instanceof o.LocalDateTime)return e;if(e instanceof o.ZonedDateTime)return e.toLocalDateTime();if(e instanceof Date)return o.LocalDateTime.from((0,o.nativeJs)(e,t));if(e instanceof o.LocalDate||a(e)||"number"==typeof e){const t=f(e);return o.LocalDateTime.of(t.year(),t.monthValue(),t.dayOfMonth(),0,0,0,0)}if("string"==typeof e)return r.test(e)?m(o.LocalDate.parse(e)):i.test(e)?o.ZonedDateTime.parse(e).toLocalDateTime():o.LocalDateTime.parse(e);throw new Error("Cannot convert value to LocalDateTime")}function l(e){if(e instanceof Date)return e;if(e instanceof o.LocalDate||e instanceof o.ZonedDateTime)return new Date(e.year(),e.monthValue()-1,e.dayOfMonth());if(e instanceof o.LocalDateTime)return new Date(e.year(),e.monthValue()-1,e.dayOfMonth(),e.hour(),e.minute(),e.second(),e.nano()/1e6);if(e instanceof o.LocalTime)return new Date(1970,1,1,e.hour(),e.minute(),e.second(),e.nano()/1e6);if("number"==typeof e||a(e))return l(f(e));if("string"==typeof e)return new Date(e);throw new Error("Cannot convert value to Date")}function s(e,t=o.ZoneId.SYSTEM){if(e instanceof o.LocalTime)return e;if(e instanceof o.LocalDateTime)return e.toLocalTime();if(e instanceof o.ZonedDateTime)return e.toLocalTime();if(e instanceof Date)return o.LocalTime.from((0,o.nativeJs)(e,t));if(function(e){return null!=e&&"object"==typeof e&&void 0!==e._hour&&void 0!==e._minute&&void 0!==e._second&&void 0!==e._nano}(e))return o.LocalTime.of(e._hour,e._minute,e._second,e._nano);if("number"==typeof e)return o.LocalTime.ofSecondOfDay(e);if("string"==typeof e)return c.test(e)?o.LocalTime.parse(e):m(e,t).toLocalTime();throw new Error("Cannot convert value to LocalTime")}let D;function d(e,{type:t=D.short,time:r=!1,date:i=!0,format:c}={type:D.short,time:!1,date:!0},u=o.ZoneId.SYSTEM){let l,s,d;if(!e)return"";if("number"==typeof e&&(l=f(e)),"string"==typeof e&&!1===r&&(l=f(e)),"string"==typeof e&&(l=m(e)),a(e)&&(l=f(e)),e instanceof Date&&(l=m(e,u)),e instanceof o.LocalDate&&(l=e),e instanceof o.LocalDateTime&&(l=e),e instanceof o.LocalTime&&(l=e),e instanceof o.ZonedDateTime&&(l=e),!l)throw new Error("Date could not be converted to a js-joda date");switch(t){case D.medium:s="MMM d, yyyy",d="h:mm a";break;case D.long:s="MMMM d, yyyy",d="h:mm a";break;case D.short:default:s="M/d/yyyy",d="h:mm a"}l instanceof o.LocalDate&&(d=""),l instanceof o.LocalTime&&(s="");let y=i?s:"";r&&(y=`${y} ${d}`.trim());const L=o.DateTimeFormatter.ofPattern(c||y).withLocale(n.Locale.ENGLISH);return l.format(L).replace(/AM|PM/,(e=>e.toLowerCase()))}function y({year:e,limitToCurrentMonth:t=!0}={}){const o=["January","February","March","April","May","June","July","August","September","October","November","December"],n=new Date,a=n.getFullYear(),r=n.getMonth();if(e){if(e>a)return[];if(e===a&&t)return o.slice(0,r+1)}return o}function L({month:e,limitToCurrentDay:t=!1,asArray:o=!1}){const n=t&&e===(new Date).getMonth()+1?(new Date).getDate():new Date(2019,e,0).getDate();if(!o)return n;const a=[];for(let e=1;e<=n;e++)a.push(e);return a}function T(e){return{time:e.get(o.ChronoField.CLOCK_HOUR_OF_AMPM).toString().concat(":",e.minute()<10?"0":"",e.minute().toString()),timeOfDay:e.hour()<12?"morning":"afternoon"}}!function(e){e.short="short",e.medium="medium",e.long="long"}(D||(D={})),module.exports=t})();
2//# sourceMappingURL=index.min.js.map
\No newline at end of file