tsgrid-ui 2.4.0 → 2.5.0
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/CHANGELOG.md +50 -0
- package/dist/tsgrid-ui.css +2 -2
- package/dist/tsgrid-ui.d.ts +15 -0
- package/dist/tsgrid-ui.es6.js +337 -311
- package/dist/tsgrid-ui.es6.js.map +1 -1
- package/dist/tsgrid-ui.es6.min.js +35 -35
- package/dist/tsgrid-ui.js +338 -312
- package/dist/tsgrid-ui.min.css +2 -2
- package/dist/tsgrid-ui.min.js +36 -36
- package/package.json +1 -1
package/dist/tsgrid-ui.es6.js
CHANGED
|
@@ -2659,6 +2659,335 @@ function bindEvents(selector, subject) {
|
|
|
2659
2659
|
});
|
|
2660
2660
|
}
|
|
2661
2661
|
|
|
2662
|
+
// src/tsutils-datetime.ts
|
|
2663
|
+
function _isDate(val, format, retDate, settings) {
|
|
2664
|
+
if (!val) return false;
|
|
2665
|
+
let dt = "Invalid Date";
|
|
2666
|
+
let month, day, year;
|
|
2667
|
+
if (format == null) format = settings.dateFormat;
|
|
2668
|
+
if (val instanceof Date) {
|
|
2669
|
+
year = val.getFullYear();
|
|
2670
|
+
month = val.getMonth() + 1;
|
|
2671
|
+
day = val.getDate();
|
|
2672
|
+
} else if (typeof val === "number" || typeof val === "string" && parseInt(val) == val && parseInt(val) > 0) {
|
|
2673
|
+
const d = new Date(parseInt(String(val)));
|
|
2674
|
+
year = d.getFullYear();
|
|
2675
|
+
month = d.getMonth() + 1;
|
|
2676
|
+
day = d.getDate();
|
|
2677
|
+
} else {
|
|
2678
|
+
let strVal = String(val);
|
|
2679
|
+
if (new RegExp("mon", "ig").test(format)) {
|
|
2680
|
+
format = format.replace(/month/ig, "m").replace(/mon/ig, "m").replace(/dd/ig, "d").replace(/[, ]/ig, "/").replace(/\/\//g, "/").toLowerCase();
|
|
2681
|
+
strVal = strVal.replace(/[, ]/ig, "/").replace(/\/\//g, "/").toLowerCase();
|
|
2682
|
+
for (let m = 0, len = settings.fullmonths.length; m < len; m++) {
|
|
2683
|
+
const t = settings.fullmonths[m] ?? "";
|
|
2684
|
+
strVal = strVal.replace(new RegExp(t, "ig"), String(m + 1)).replace(new RegExp(t.substr(0, 3), "ig"), String(m + 1));
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
const tmp = strVal.replace(/-/g, "/").replace(/\./g, "/").toLowerCase().split("/");
|
|
2688
|
+
const tmp2 = format.replace(/-/g, "/").replace(/\./g, "/").toLowerCase();
|
|
2689
|
+
if (tmp2 === "mm/dd/yyyy") {
|
|
2690
|
+
month = tmp[0];
|
|
2691
|
+
day = tmp[1];
|
|
2692
|
+
year = tmp[2];
|
|
2693
|
+
}
|
|
2694
|
+
if (tmp2 === "m/d/yyyy") {
|
|
2695
|
+
month = tmp[0];
|
|
2696
|
+
day = tmp[1];
|
|
2697
|
+
year = tmp[2];
|
|
2698
|
+
}
|
|
2699
|
+
if (tmp2 === "dd/mm/yyyy") {
|
|
2700
|
+
month = tmp[1];
|
|
2701
|
+
day = tmp[0];
|
|
2702
|
+
year = tmp[2];
|
|
2703
|
+
}
|
|
2704
|
+
if (tmp2 === "d/m/yyyy") {
|
|
2705
|
+
month = tmp[1];
|
|
2706
|
+
day = tmp[0];
|
|
2707
|
+
year = tmp[2];
|
|
2708
|
+
}
|
|
2709
|
+
if (tmp2 === "yyyy/dd/mm") {
|
|
2710
|
+
month = tmp[2];
|
|
2711
|
+
day = tmp[1];
|
|
2712
|
+
year = tmp[0];
|
|
2713
|
+
}
|
|
2714
|
+
if (tmp2 === "yyyy/d/m") {
|
|
2715
|
+
month = tmp[2];
|
|
2716
|
+
day = tmp[1];
|
|
2717
|
+
year = tmp[0];
|
|
2718
|
+
}
|
|
2719
|
+
if (tmp2 === "yyyy/mm/dd") {
|
|
2720
|
+
month = tmp[1];
|
|
2721
|
+
day = tmp[2];
|
|
2722
|
+
year = tmp[0];
|
|
2723
|
+
}
|
|
2724
|
+
if (tmp2 === "yyyy/m/d") {
|
|
2725
|
+
month = tmp[1];
|
|
2726
|
+
day = tmp[2];
|
|
2727
|
+
year = tmp[0];
|
|
2728
|
+
}
|
|
2729
|
+
if (tmp2 === "mm/dd/yy") {
|
|
2730
|
+
month = tmp[0];
|
|
2731
|
+
day = tmp[1];
|
|
2732
|
+
year = tmp[2];
|
|
2733
|
+
}
|
|
2734
|
+
if (tmp2 === "m/d/yy") {
|
|
2735
|
+
month = tmp[0];
|
|
2736
|
+
day = tmp[1];
|
|
2737
|
+
year = parseInt(tmp[2] ?? "0") + 1900;
|
|
2738
|
+
}
|
|
2739
|
+
if (tmp2 === "dd/mm/yy") {
|
|
2740
|
+
month = tmp[1];
|
|
2741
|
+
day = tmp[0];
|
|
2742
|
+
year = parseInt(tmp[2] ?? "0") + 1900;
|
|
2743
|
+
}
|
|
2744
|
+
if (tmp2 === "d/m/yy") {
|
|
2745
|
+
month = tmp[1];
|
|
2746
|
+
day = tmp[0];
|
|
2747
|
+
year = parseInt(tmp[2] ?? "0") + 1900;
|
|
2748
|
+
}
|
|
2749
|
+
if (tmp2 === "yy/dd/mm") {
|
|
2750
|
+
month = tmp[2];
|
|
2751
|
+
day = tmp[1];
|
|
2752
|
+
year = parseInt(tmp[0] ?? "0") + 1900;
|
|
2753
|
+
}
|
|
2754
|
+
if (tmp2 === "yy/d/m") {
|
|
2755
|
+
month = tmp[2];
|
|
2756
|
+
day = tmp[1];
|
|
2757
|
+
year = parseInt(tmp[0] ?? "0") + 1900;
|
|
2758
|
+
}
|
|
2759
|
+
if (tmp2 === "yy/mm/dd") {
|
|
2760
|
+
month = tmp[1];
|
|
2761
|
+
day = tmp[2];
|
|
2762
|
+
year = parseInt(tmp[0] ?? "0") + 1900;
|
|
2763
|
+
}
|
|
2764
|
+
if (tmp2 === "yy/m/d") {
|
|
2765
|
+
month = tmp[1];
|
|
2766
|
+
day = tmp[2];
|
|
2767
|
+
year = parseInt(tmp[0] ?? "0") + 1900;
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
if (!isInt(year)) return false;
|
|
2771
|
+
if (!isInt(month)) return false;
|
|
2772
|
+
if (!isInt(day)) return false;
|
|
2773
|
+
const numYear = +(year ?? 0);
|
|
2774
|
+
const numMonth = +(month ?? 0);
|
|
2775
|
+
const numDay = +(day ?? 0);
|
|
2776
|
+
dt = new Date(numYear, numMonth - 1, numDay);
|
|
2777
|
+
dt.setFullYear(numYear);
|
|
2778
|
+
if (numMonth == null) return false;
|
|
2779
|
+
if (String(dt) === "Invalid Date") return false;
|
|
2780
|
+
if (dt.getMonth() + 1 !== numMonth || dt.getDate() !== numDay || dt.getFullYear() !== numYear) return false;
|
|
2781
|
+
if (retDate === true) return dt;
|
|
2782
|
+
else return true;
|
|
2783
|
+
}
|
|
2784
|
+
function _isTime(val, retTime) {
|
|
2785
|
+
if (val == null) return false;
|
|
2786
|
+
let max;
|
|
2787
|
+
let strVal = String(val).toUpperCase();
|
|
2788
|
+
const am = strVal.indexOf("AM") >= 0;
|
|
2789
|
+
const pm = strVal.indexOf("PM") >= 0;
|
|
2790
|
+
const ampm = pm || am;
|
|
2791
|
+
if (ampm) max = 12;
|
|
2792
|
+
else max = 24;
|
|
2793
|
+
strVal = strVal.replace("AM", "").replace("PM", "").trim();
|
|
2794
|
+
const tmp = strVal.split(":");
|
|
2795
|
+
const tmp0 = tmp[0] ?? "", tmp1 = tmp[1] ?? "", tmp2 = tmp[2] ?? "";
|
|
2796
|
+
let h = parseInt(tmp0 || "0");
|
|
2797
|
+
const m = parseInt(tmp1 || "0"), s = parseInt(tmp2 || "0");
|
|
2798
|
+
if ((!ampm || tmp.length !== 1) && tmp.length !== 2 && tmp.length !== 3) {
|
|
2799
|
+
return false;
|
|
2800
|
+
}
|
|
2801
|
+
if (tmp0 === "" || h < 0 || h > max || !isInt(tmp0) || tmp0.length > 2) {
|
|
2802
|
+
return false;
|
|
2803
|
+
}
|
|
2804
|
+
if (tmp.length > 1 && (tmp1 === "" || m < 0 || m > 59 || !isInt(tmp1) || tmp1.length !== 2)) {
|
|
2805
|
+
return false;
|
|
2806
|
+
}
|
|
2807
|
+
if (tmp.length > 2 && (tmp2 === "" || s < 0 || s > 59 || !isInt(tmp2) || tmp2.length !== 2)) {
|
|
2808
|
+
return false;
|
|
2809
|
+
}
|
|
2810
|
+
if (!ampm && max === h && (m !== 0 || s !== 0)) {
|
|
2811
|
+
return false;
|
|
2812
|
+
}
|
|
2813
|
+
if (ampm && tmp.length === 1 && h === 0) {
|
|
2814
|
+
return false;
|
|
2815
|
+
}
|
|
2816
|
+
if (retTime === true) {
|
|
2817
|
+
if (pm && h !== 12) h += 12;
|
|
2818
|
+
if (am && h === 12) h += 12;
|
|
2819
|
+
return {
|
|
2820
|
+
hours: h,
|
|
2821
|
+
minutes: m,
|
|
2822
|
+
seconds: s
|
|
2823
|
+
};
|
|
2824
|
+
}
|
|
2825
|
+
return true;
|
|
2826
|
+
}
|
|
2827
|
+
function _isDateTime(val, format, retDate, settings) {
|
|
2828
|
+
if (val instanceof Date) {
|
|
2829
|
+
if (retDate !== true) return true;
|
|
2830
|
+
return val;
|
|
2831
|
+
}
|
|
2832
|
+
const intVal = parseInt(String(val));
|
|
2833
|
+
if (intVal === val) {
|
|
2834
|
+
if (intVal < 0) return false;
|
|
2835
|
+
else if (retDate !== true) return true;
|
|
2836
|
+
else return new Date(intVal);
|
|
2837
|
+
}
|
|
2838
|
+
const strVal = String(val);
|
|
2839
|
+
const tmp = strVal.indexOf(" ");
|
|
2840
|
+
if (tmp < 0) {
|
|
2841
|
+
if (strVal.indexOf("T") < 0 || String(new Date(strVal)) == "Invalid Date") return false;
|
|
2842
|
+
else if (retDate !== true) return true;
|
|
2843
|
+
else return new Date(strVal);
|
|
2844
|
+
} else {
|
|
2845
|
+
if (format == null) format = settings.datetimeFormat;
|
|
2846
|
+
const formats = format.split("|");
|
|
2847
|
+
const values = [strVal.substr(0, tmp), strVal.substr(tmp).trim()];
|
|
2848
|
+
if (formats[0] != null) formats[0] = formats[0].trim();
|
|
2849
|
+
if (formats[1]) formats[1] = formats[1].trim();
|
|
2850
|
+
const tmp1 = _isDate(values[0], formats[0], true, settings);
|
|
2851
|
+
const tmp2 = _isTime(values[1], true);
|
|
2852
|
+
if (tmp1 !== false && tmp2 !== false) {
|
|
2853
|
+
if (retDate !== true) return true;
|
|
2854
|
+
const dt1 = tmp1;
|
|
2855
|
+
const t2 = tmp2;
|
|
2856
|
+
dt1.setHours(t2.hours);
|
|
2857
|
+
dt1.setMinutes(t2.minutes);
|
|
2858
|
+
dt1.setSeconds(t2.seconds);
|
|
2859
|
+
return dt1;
|
|
2860
|
+
} else {
|
|
2861
|
+
return false;
|
|
2862
|
+
}
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2865
|
+
function _age(dateStr) {
|
|
2866
|
+
let d1;
|
|
2867
|
+
if (dateStr === "" || dateStr == null) return "";
|
|
2868
|
+
if (dateStr instanceof Date) {
|
|
2869
|
+
d1 = dateStr;
|
|
2870
|
+
} else if (typeof dateStr === "number" || typeof dateStr === "string" && parseInt(dateStr) == dateStr && parseInt(dateStr) > 0) {
|
|
2871
|
+
d1 = new Date(parseInt(String(dateStr)));
|
|
2872
|
+
} else {
|
|
2873
|
+
d1 = new Date(String(dateStr));
|
|
2874
|
+
}
|
|
2875
|
+
if (String(d1) === "Invalid Date") return "";
|
|
2876
|
+
const d2 = /* @__PURE__ */ new Date();
|
|
2877
|
+
const sec = (d2.getTime() - d1.getTime()) / 1e3;
|
|
2878
|
+
let amount = 0;
|
|
2879
|
+
let type = "";
|
|
2880
|
+
if (sec < 0) {
|
|
2881
|
+
amount = 0;
|
|
2882
|
+
type = "sec";
|
|
2883
|
+
} else if (sec < 60) {
|
|
2884
|
+
amount = Math.floor(sec);
|
|
2885
|
+
type = "sec";
|
|
2886
|
+
if (sec < 0) {
|
|
2887
|
+
amount = 0;
|
|
2888
|
+
type = "sec";
|
|
2889
|
+
}
|
|
2890
|
+
} else if (sec < 60 * 60) {
|
|
2891
|
+
amount = Math.floor(sec / 60);
|
|
2892
|
+
type = "min";
|
|
2893
|
+
} else if (sec < 24 * 60 * 60) {
|
|
2894
|
+
amount = Math.floor(sec / 60 / 60);
|
|
2895
|
+
type = "hour";
|
|
2896
|
+
} else if (sec < 30 * 24 * 60 * 60) {
|
|
2897
|
+
amount = Math.floor(sec / 24 / 60 / 60);
|
|
2898
|
+
type = "day";
|
|
2899
|
+
} else if (sec < 365 * 24 * 60 * 60) {
|
|
2900
|
+
amount = Math.floor(sec / 30 / 24 / 60 / 60 * 10) / 10;
|
|
2901
|
+
type = "month";
|
|
2902
|
+
} else if (sec < 365 * 4 * 24 * 60 * 60) {
|
|
2903
|
+
amount = Math.floor(sec / 365 / 24 / 60 / 60 * 10) / 10;
|
|
2904
|
+
type = "year";
|
|
2905
|
+
} else if (sec >= 365 * 4 * 24 * 60 * 60) {
|
|
2906
|
+
amount = Math.floor(sec / 365.25 / 24 / 60 / 60 * 10) / 10;
|
|
2907
|
+
type = "year";
|
|
2908
|
+
}
|
|
2909
|
+
return amount + " " + type + (amount > 1 ? "s" : "");
|
|
2910
|
+
}
|
|
2911
|
+
function _interval(value) {
|
|
2912
|
+
let ret = "";
|
|
2913
|
+
if (value < 100) {
|
|
2914
|
+
ret = "< 0.01 sec";
|
|
2915
|
+
} else if (value < 1e3) {
|
|
2916
|
+
ret = Math.floor(value / 10) / 100 + " sec";
|
|
2917
|
+
} else if (value < 1e4) {
|
|
2918
|
+
ret = Math.floor(value / 100) / 10 + " sec";
|
|
2919
|
+
} else if (value < 6e4) {
|
|
2920
|
+
ret = Math.floor(value / 1e3) + " secs";
|
|
2921
|
+
} else if (value < 36e5) {
|
|
2922
|
+
ret = Math.floor(value / 6e4) + " mins";
|
|
2923
|
+
} else if (value < 864e5) {
|
|
2924
|
+
ret = Math.floor(value / 36e5 * 10) / 10 + " hours";
|
|
2925
|
+
} else if (value < 2628e6) {
|
|
2926
|
+
ret = Math.floor(value / 864e5 * 10) / 10 + " days";
|
|
2927
|
+
} else if (value < 31536e6) {
|
|
2928
|
+
ret = Math.floor(value / 2628e6 * 10) / 10 + " months";
|
|
2929
|
+
} else {
|
|
2930
|
+
ret = Math.floor(value / 31536e5) / 10 + " years";
|
|
2931
|
+
}
|
|
2932
|
+
return ret;
|
|
2933
|
+
}
|
|
2934
|
+
function _formatDate(dateStr, format, settings) {
|
|
2935
|
+
if (!format) format = settings.dateFormat;
|
|
2936
|
+
if (dateStr === "" || dateStr == null || typeof dateStr === "object" && !dateStr.getMonth) return "";
|
|
2937
|
+
let dt = new Date(dateStr);
|
|
2938
|
+
if (isInt(dateStr)) dt = new Date(Number(dateStr));
|
|
2939
|
+
if (String(dt) === "Invalid Date") return "";
|
|
2940
|
+
const year = dt.getFullYear();
|
|
2941
|
+
const month = dt.getMonth();
|
|
2942
|
+
const date = dt.getDate();
|
|
2943
|
+
return format.toLowerCase().replace("month", settings.fullmonths[month] ?? "").replace("mon", settings.shortmonths[month] ?? "").replace(/yyyy/g, ("000" + year).slice(-4)).replace(/yyy/g, ("000" + year).slice(-4)).replace(/yy/g, ("0" + year).slice(-2)).replace(/(^|[^a-z$])y/g, "$1" + year).replace(/mm/g, ("0" + (month + 1)).slice(-2)).replace(/dd/g, ("0" + date).slice(-2)).replace(/th/g, date == 1 ? "st" : "th").replace(/th/g, date == 2 ? "nd" : "th").replace(/th/g, date == 3 ? "rd" : "th").replace(/(^|[^a-z$])m/g, "$1" + (month + 1)).replace(/(^|[^a-z$])d/g, "$1" + date);
|
|
2944
|
+
}
|
|
2945
|
+
function _formatTime(dateStr, format, settings) {
|
|
2946
|
+
if (!format) format = settings.timeFormat;
|
|
2947
|
+
if (dateStr === "" || dateStr == null || typeof dateStr === "object" && !dateStr.getMonth) return "";
|
|
2948
|
+
let dt = new Date(dateStr);
|
|
2949
|
+
if (isInt(dateStr)) dt = new Date(Number(dateStr));
|
|
2950
|
+
if (_isTime(dateStr)) {
|
|
2951
|
+
const tmp = _isTime(dateStr, true);
|
|
2952
|
+
dt = /* @__PURE__ */ new Date();
|
|
2953
|
+
dt.setHours(tmp.hours);
|
|
2954
|
+
dt.setMinutes(tmp.minutes);
|
|
2955
|
+
}
|
|
2956
|
+
if (String(dt) === "Invalid Date") return "";
|
|
2957
|
+
if (format == "h12") format = "hh:mi pm";
|
|
2958
|
+
let type = "am";
|
|
2959
|
+
let hour = dt.getHours();
|
|
2960
|
+
const h24 = dt.getHours();
|
|
2961
|
+
let min = dt.getMinutes();
|
|
2962
|
+
let sec = dt.getSeconds();
|
|
2963
|
+
if (min < 10) min = "0" + min;
|
|
2964
|
+
if (sec < 10) sec = "0" + sec;
|
|
2965
|
+
if (format.indexOf("am") !== -1 || format.indexOf("pm") !== -1) {
|
|
2966
|
+
if (hour >= 12) type = "pm";
|
|
2967
|
+
if (hour > 12) hour = hour - 12;
|
|
2968
|
+
if (hour === 0) hour = 12;
|
|
2969
|
+
}
|
|
2970
|
+
const hourStr = String(hour);
|
|
2971
|
+
const minStr = String(min);
|
|
2972
|
+
const secStr = String(sec);
|
|
2973
|
+
const h24Str = String(h24);
|
|
2974
|
+
return format.toLowerCase().replace("am", type).replace("pm", type).replace("hhh", Number(hour) < 10 ? "0" + hourStr : hourStr).replace("hh24", h24 < 10 ? "0" + h24Str : h24Str).replace("h24", h24Str).replace("hh", hourStr).replace("mm", minStr).replace("mi", minStr).replace("ss", secStr).replace(/(^|[^a-z$])h/g, "$1" + hourStr).replace(/(^|[^a-z$])m/g, "$1" + minStr).replace(/(^|[^a-z$])s/g, "$1" + secStr);
|
|
2975
|
+
}
|
|
2976
|
+
function _formatDateTime(dateStr, format, settings) {
|
|
2977
|
+
let fmt;
|
|
2978
|
+
if (dateStr === "" || dateStr == null || typeof dateStr === "object" && !dateStr.getMonth) return "";
|
|
2979
|
+
if (typeof format !== "string") {
|
|
2980
|
+
fmt = [settings.dateFormat, settings.timeFormat];
|
|
2981
|
+
} else {
|
|
2982
|
+
fmt = format.split("|");
|
|
2983
|
+
if (fmt[0] != null) fmt[0] = fmt[0].trim();
|
|
2984
|
+
fmt[1] = fmt.length > 1 ? (fmt[1] ?? "").trim() : settings.timeFormat;
|
|
2985
|
+
}
|
|
2986
|
+
if (fmt[1] === "h12") fmt[1] = "h:m pm";
|
|
2987
|
+
if (fmt[1] === "h24") fmt[1] = "h24:m";
|
|
2988
|
+
return _formatDate(dateStr, fmt[0], settings) + " " + _formatTime(dateStr, fmt[1], settings);
|
|
2989
|
+
}
|
|
2990
|
+
|
|
2662
2991
|
// src/tsutils.ts
|
|
2663
2992
|
var query7 = query;
|
|
2664
2993
|
var Utils = class {
|
|
@@ -2859,275 +3188,19 @@ var Utils = class {
|
|
|
2859
3188
|
return isIpAddress(val);
|
|
2860
3189
|
}
|
|
2861
3190
|
isDate(val, format, retDate) {
|
|
2862
|
-
|
|
2863
|
-
let dt = "Invalid Date";
|
|
2864
|
-
let month, day, year;
|
|
2865
|
-
if (format == null) format = this.settings.dateFormat;
|
|
2866
|
-
if (val instanceof Date) {
|
|
2867
|
-
year = val.getFullYear();
|
|
2868
|
-
month = val.getMonth() + 1;
|
|
2869
|
-
day = val.getDate();
|
|
2870
|
-
} else if (typeof val === "number" || typeof val === "string" && parseInt(val) == val && parseInt(val) > 0) {
|
|
2871
|
-
const d = new Date(parseInt(String(val)));
|
|
2872
|
-
year = d.getFullYear();
|
|
2873
|
-
month = d.getMonth() + 1;
|
|
2874
|
-
day = d.getDate();
|
|
2875
|
-
} else {
|
|
2876
|
-
let strVal = String(val);
|
|
2877
|
-
if (new RegExp("mon", "ig").test(format)) {
|
|
2878
|
-
format = format.replace(/month/ig, "m").replace(/mon/ig, "m").replace(/dd/ig, "d").replace(/[, ]/ig, "/").replace(/\/\//g, "/").toLowerCase();
|
|
2879
|
-
strVal = strVal.replace(/[, ]/ig, "/").replace(/\/\//g, "/").toLowerCase();
|
|
2880
|
-
for (let m = 0, len = this.settings.fullmonths.length; m < len; m++) {
|
|
2881
|
-
const t = this.settings.fullmonths[m] ?? "";
|
|
2882
|
-
strVal = strVal.replace(new RegExp(t, "ig"), String(m + 1)).replace(new RegExp(t.substr(0, 3), "ig"), String(m + 1));
|
|
2883
|
-
}
|
|
2884
|
-
}
|
|
2885
|
-
const tmp = strVal.replace(/-/g, "/").replace(/\./g, "/").toLowerCase().split("/");
|
|
2886
|
-
const tmp2 = format.replace(/-/g, "/").replace(/\./g, "/").toLowerCase();
|
|
2887
|
-
if (tmp2 === "mm/dd/yyyy") {
|
|
2888
|
-
month = tmp[0];
|
|
2889
|
-
day = tmp[1];
|
|
2890
|
-
year = tmp[2];
|
|
2891
|
-
}
|
|
2892
|
-
if (tmp2 === "m/d/yyyy") {
|
|
2893
|
-
month = tmp[0];
|
|
2894
|
-
day = tmp[1];
|
|
2895
|
-
year = tmp[2];
|
|
2896
|
-
}
|
|
2897
|
-
if (tmp2 === "dd/mm/yyyy") {
|
|
2898
|
-
month = tmp[1];
|
|
2899
|
-
day = tmp[0];
|
|
2900
|
-
year = tmp[2];
|
|
2901
|
-
}
|
|
2902
|
-
if (tmp2 === "d/m/yyyy") {
|
|
2903
|
-
month = tmp[1];
|
|
2904
|
-
day = tmp[0];
|
|
2905
|
-
year = tmp[2];
|
|
2906
|
-
}
|
|
2907
|
-
if (tmp2 === "yyyy/dd/mm") {
|
|
2908
|
-
month = tmp[2];
|
|
2909
|
-
day = tmp[1];
|
|
2910
|
-
year = tmp[0];
|
|
2911
|
-
}
|
|
2912
|
-
if (tmp2 === "yyyy/d/m") {
|
|
2913
|
-
month = tmp[2];
|
|
2914
|
-
day = tmp[1];
|
|
2915
|
-
year = tmp[0];
|
|
2916
|
-
}
|
|
2917
|
-
if (tmp2 === "yyyy/mm/dd") {
|
|
2918
|
-
month = tmp[1];
|
|
2919
|
-
day = tmp[2];
|
|
2920
|
-
year = tmp[0];
|
|
2921
|
-
}
|
|
2922
|
-
if (tmp2 === "yyyy/m/d") {
|
|
2923
|
-
month = tmp[1];
|
|
2924
|
-
day = tmp[2];
|
|
2925
|
-
year = tmp[0];
|
|
2926
|
-
}
|
|
2927
|
-
if (tmp2 === "mm/dd/yy") {
|
|
2928
|
-
month = tmp[0];
|
|
2929
|
-
day = tmp[1];
|
|
2930
|
-
year = tmp[2];
|
|
2931
|
-
}
|
|
2932
|
-
if (tmp2 === "m/d/yy") {
|
|
2933
|
-
month = tmp[0];
|
|
2934
|
-
day = tmp[1];
|
|
2935
|
-
year = parseInt(tmp[2] ?? "0") + 1900;
|
|
2936
|
-
}
|
|
2937
|
-
if (tmp2 === "dd/mm/yy") {
|
|
2938
|
-
month = tmp[1];
|
|
2939
|
-
day = tmp[0];
|
|
2940
|
-
year = parseInt(tmp[2] ?? "0") + 1900;
|
|
2941
|
-
}
|
|
2942
|
-
if (tmp2 === "d/m/yy") {
|
|
2943
|
-
month = tmp[1];
|
|
2944
|
-
day = tmp[0];
|
|
2945
|
-
year = parseInt(tmp[2] ?? "0") + 1900;
|
|
2946
|
-
}
|
|
2947
|
-
if (tmp2 === "yy/dd/mm") {
|
|
2948
|
-
month = tmp[2];
|
|
2949
|
-
day = tmp[1];
|
|
2950
|
-
year = parseInt(tmp[0] ?? "0") + 1900;
|
|
2951
|
-
}
|
|
2952
|
-
if (tmp2 === "yy/d/m") {
|
|
2953
|
-
month = tmp[2];
|
|
2954
|
-
day = tmp[1];
|
|
2955
|
-
year = parseInt(tmp[0] ?? "0") + 1900;
|
|
2956
|
-
}
|
|
2957
|
-
if (tmp2 === "yy/mm/dd") {
|
|
2958
|
-
month = tmp[1];
|
|
2959
|
-
day = tmp[2];
|
|
2960
|
-
year = parseInt(tmp[0] ?? "0") + 1900;
|
|
2961
|
-
}
|
|
2962
|
-
if (tmp2 === "yy/m/d") {
|
|
2963
|
-
month = tmp[1];
|
|
2964
|
-
day = tmp[2];
|
|
2965
|
-
year = parseInt(tmp[0] ?? "0") + 1900;
|
|
2966
|
-
}
|
|
2967
|
-
}
|
|
2968
|
-
if (!this.isInt(year)) return false;
|
|
2969
|
-
if (!this.isInt(month)) return false;
|
|
2970
|
-
if (!this.isInt(day)) return false;
|
|
2971
|
-
const numYear = +(year ?? 0);
|
|
2972
|
-
const numMonth = +(month ?? 0);
|
|
2973
|
-
const numDay = +(day ?? 0);
|
|
2974
|
-
dt = new Date(numYear, numMonth - 1, numDay);
|
|
2975
|
-
dt.setFullYear(numYear);
|
|
2976
|
-
if (numMonth == null) return false;
|
|
2977
|
-
if (String(dt) === "Invalid Date") return false;
|
|
2978
|
-
if (dt.getMonth() + 1 !== numMonth || dt.getDate() !== numDay || dt.getFullYear() !== numYear) return false;
|
|
2979
|
-
if (retDate === true) return dt;
|
|
2980
|
-
else return true;
|
|
3191
|
+
return _isDate(val, format, retDate, this.settings);
|
|
2981
3192
|
}
|
|
2982
3193
|
isTime(val, retTime) {
|
|
2983
|
-
|
|
2984
|
-
let max;
|
|
2985
|
-
let strVal = String(val).toUpperCase();
|
|
2986
|
-
const am = strVal.indexOf("AM") >= 0;
|
|
2987
|
-
const pm = strVal.indexOf("PM") >= 0;
|
|
2988
|
-
const ampm = pm || am;
|
|
2989
|
-
if (ampm) max = 12;
|
|
2990
|
-
else max = 24;
|
|
2991
|
-
strVal = strVal.replace("AM", "").replace("PM", "").trim();
|
|
2992
|
-
const tmp = strVal.split(":");
|
|
2993
|
-
const tmp0 = tmp[0] ?? "", tmp1 = tmp[1] ?? "", tmp2 = tmp[2] ?? "";
|
|
2994
|
-
let h = parseInt(tmp0 || "0");
|
|
2995
|
-
const m = parseInt(tmp1 || "0"), s = parseInt(tmp2 || "0");
|
|
2996
|
-
if ((!ampm || tmp.length !== 1) && tmp.length !== 2 && tmp.length !== 3) {
|
|
2997
|
-
return false;
|
|
2998
|
-
}
|
|
2999
|
-
if (tmp0 === "" || h < 0 || h > max || !this.isInt(tmp0) || tmp0.length > 2) {
|
|
3000
|
-
return false;
|
|
3001
|
-
}
|
|
3002
|
-
if (tmp.length > 1 && (tmp1 === "" || m < 0 || m > 59 || !this.isInt(tmp1) || tmp1.length !== 2)) {
|
|
3003
|
-
return false;
|
|
3004
|
-
}
|
|
3005
|
-
if (tmp.length > 2 && (tmp2 === "" || s < 0 || s > 59 || !this.isInt(tmp2) || tmp2.length !== 2)) {
|
|
3006
|
-
return false;
|
|
3007
|
-
}
|
|
3008
|
-
if (!ampm && max === h && (m !== 0 || s !== 0)) {
|
|
3009
|
-
return false;
|
|
3010
|
-
}
|
|
3011
|
-
if (ampm && tmp.length === 1 && h === 0) {
|
|
3012
|
-
return false;
|
|
3013
|
-
}
|
|
3014
|
-
if (retTime === true) {
|
|
3015
|
-
if (pm && h !== 12) h += 12;
|
|
3016
|
-
if (am && h === 12) h += 12;
|
|
3017
|
-
return {
|
|
3018
|
-
hours: h,
|
|
3019
|
-
minutes: m,
|
|
3020
|
-
seconds: s
|
|
3021
|
-
};
|
|
3022
|
-
}
|
|
3023
|
-
return true;
|
|
3194
|
+
return _isTime(val, retTime);
|
|
3024
3195
|
}
|
|
3025
3196
|
isDateTime(val, format, retDate) {
|
|
3026
|
-
|
|
3027
|
-
if (retDate !== true) return true;
|
|
3028
|
-
return val;
|
|
3029
|
-
}
|
|
3030
|
-
const intVal = parseInt(String(val));
|
|
3031
|
-
if (intVal === val) {
|
|
3032
|
-
if (intVal < 0) return false;
|
|
3033
|
-
else if (retDate !== true) return true;
|
|
3034
|
-
else return new Date(intVal);
|
|
3035
|
-
}
|
|
3036
|
-
const strVal = String(val);
|
|
3037
|
-
const tmp = strVal.indexOf(" ");
|
|
3038
|
-
if (tmp < 0) {
|
|
3039
|
-
if (strVal.indexOf("T") < 0 || String(new Date(strVal)) == "Invalid Date") return false;
|
|
3040
|
-
else if (retDate !== true) return true;
|
|
3041
|
-
else return new Date(strVal);
|
|
3042
|
-
} else {
|
|
3043
|
-
if (format == null) format = this.settings.datetimeFormat;
|
|
3044
|
-
const formats = format.split("|");
|
|
3045
|
-
const values = [strVal.substr(0, tmp), strVal.substr(tmp).trim()];
|
|
3046
|
-
if (formats[0] != null) formats[0] = formats[0].trim();
|
|
3047
|
-
if (formats[1]) formats[1] = formats[1].trim();
|
|
3048
|
-
const tmp1 = this.isDate(values[0], formats[0], true);
|
|
3049
|
-
const tmp2 = this.isTime(values[1], true);
|
|
3050
|
-
if (tmp1 !== false && tmp2 !== false) {
|
|
3051
|
-
if (retDate !== true) return true;
|
|
3052
|
-
const dt1 = tmp1;
|
|
3053
|
-
const t2 = tmp2;
|
|
3054
|
-
dt1.setHours(t2.hours);
|
|
3055
|
-
dt1.setMinutes(t2.minutes);
|
|
3056
|
-
dt1.setSeconds(t2.seconds);
|
|
3057
|
-
return dt1;
|
|
3058
|
-
} else {
|
|
3059
|
-
return false;
|
|
3060
|
-
}
|
|
3061
|
-
}
|
|
3197
|
+
return _isDateTime(val, format, retDate, this.settings);
|
|
3062
3198
|
}
|
|
3063
3199
|
age(dateStr) {
|
|
3064
|
-
|
|
3065
|
-
if (dateStr === "" || dateStr == null) return "";
|
|
3066
|
-
if (dateStr instanceof Date) {
|
|
3067
|
-
d1 = dateStr;
|
|
3068
|
-
} else if (typeof dateStr === "number" || typeof dateStr === "string" && parseInt(dateStr) == dateStr && parseInt(dateStr) > 0) {
|
|
3069
|
-
d1 = new Date(parseInt(String(dateStr)));
|
|
3070
|
-
} else {
|
|
3071
|
-
d1 = new Date(String(dateStr));
|
|
3072
|
-
}
|
|
3073
|
-
if (String(d1) === "Invalid Date") return "";
|
|
3074
|
-
const d2 = /* @__PURE__ */ new Date();
|
|
3075
|
-
const sec = (d2.getTime() - d1.getTime()) / 1e3;
|
|
3076
|
-
let amount = 0;
|
|
3077
|
-
let type = "";
|
|
3078
|
-
if (sec < 0) {
|
|
3079
|
-
amount = 0;
|
|
3080
|
-
type = "sec";
|
|
3081
|
-
} else if (sec < 60) {
|
|
3082
|
-
amount = Math.floor(sec);
|
|
3083
|
-
type = "sec";
|
|
3084
|
-
if (sec < 0) {
|
|
3085
|
-
amount = 0;
|
|
3086
|
-
type = "sec";
|
|
3087
|
-
}
|
|
3088
|
-
} else if (sec < 60 * 60) {
|
|
3089
|
-
amount = Math.floor(sec / 60);
|
|
3090
|
-
type = "min";
|
|
3091
|
-
} else if (sec < 24 * 60 * 60) {
|
|
3092
|
-
amount = Math.floor(sec / 60 / 60);
|
|
3093
|
-
type = "hour";
|
|
3094
|
-
} else if (sec < 30 * 24 * 60 * 60) {
|
|
3095
|
-
amount = Math.floor(sec / 24 / 60 / 60);
|
|
3096
|
-
type = "day";
|
|
3097
|
-
} else if (sec < 365 * 24 * 60 * 60) {
|
|
3098
|
-
amount = Math.floor(sec / 30 / 24 / 60 / 60 * 10) / 10;
|
|
3099
|
-
type = "month";
|
|
3100
|
-
} else if (sec < 365 * 4 * 24 * 60 * 60) {
|
|
3101
|
-
amount = Math.floor(sec / 365 / 24 / 60 / 60 * 10) / 10;
|
|
3102
|
-
type = "year";
|
|
3103
|
-
} else if (sec >= 365 * 4 * 24 * 60 * 60) {
|
|
3104
|
-
amount = Math.floor(sec / 365.25 / 24 / 60 / 60 * 10) / 10;
|
|
3105
|
-
type = "year";
|
|
3106
|
-
}
|
|
3107
|
-
return amount + " " + type + (amount > 1 ? "s" : "");
|
|
3200
|
+
return _age(dateStr);
|
|
3108
3201
|
}
|
|
3109
3202
|
interval(value) {
|
|
3110
|
-
|
|
3111
|
-
if (value < 100) {
|
|
3112
|
-
ret = "< 0.01 sec";
|
|
3113
|
-
} else if (value < 1e3) {
|
|
3114
|
-
ret = Math.floor(value / 10) / 100 + " sec";
|
|
3115
|
-
} else if (value < 1e4) {
|
|
3116
|
-
ret = Math.floor(value / 100) / 10 + " sec";
|
|
3117
|
-
} else if (value < 6e4) {
|
|
3118
|
-
ret = Math.floor(value / 1e3) + " secs";
|
|
3119
|
-
} else if (value < 36e5) {
|
|
3120
|
-
ret = Math.floor(value / 6e4) + " mins";
|
|
3121
|
-
} else if (value < 864e5) {
|
|
3122
|
-
ret = Math.floor(value / 36e5 * 10) / 10 + " hours";
|
|
3123
|
-
} else if (value < 2628e6) {
|
|
3124
|
-
ret = Math.floor(value / 864e5 * 10) / 10 + " days";
|
|
3125
|
-
} else if (value < 31536e6) {
|
|
3126
|
-
ret = Math.floor(value / 2628e6 * 10) / 10 + " months";
|
|
3127
|
-
} else {
|
|
3128
|
-
ret = Math.floor(value / 31536e5) / 10 + " years";
|
|
3129
|
-
}
|
|
3130
|
-
return ret;
|
|
3203
|
+
return _interval(value);
|
|
3131
3204
|
}
|
|
3132
3205
|
date(dateStr) {
|
|
3133
3206
|
if (dateStr === "" || dateStr == null || typeof dateStr === "object" && !dateStr.getMonth) return "";
|
|
@@ -3170,60 +3243,13 @@ var Utils = class {
|
|
|
3170
3243
|
return parseFloat(String(val)).toLocaleString(this.settings.locale, options);
|
|
3171
3244
|
}
|
|
3172
3245
|
formatDate(dateStr, format) {
|
|
3173
|
-
|
|
3174
|
-
if (dateStr === "" || dateStr == null || typeof dateStr === "object" && !dateStr.getMonth) return "";
|
|
3175
|
-
let dt = new Date(dateStr);
|
|
3176
|
-
if (this.isInt(dateStr)) dt = new Date(Number(dateStr));
|
|
3177
|
-
if (String(dt) === "Invalid Date") return "";
|
|
3178
|
-
const year = dt.getFullYear();
|
|
3179
|
-
const month = dt.getMonth();
|
|
3180
|
-
const date = dt.getDate();
|
|
3181
|
-
return format.toLowerCase().replace("month", this.settings.fullmonths[month] ?? "").replace("mon", this.settings.shortmonths[month] ?? "").replace(/yyyy/g, ("000" + year).slice(-4)).replace(/yyy/g, ("000" + year).slice(-4)).replace(/yy/g, ("0" + year).slice(-2)).replace(/(^|[^a-z$])y/g, "$1" + year).replace(/mm/g, ("0" + (month + 1)).slice(-2)).replace(/dd/g, ("0" + date).slice(-2)).replace(/th/g, date == 1 ? "st" : "th").replace(/th/g, date == 2 ? "nd" : "th").replace(/th/g, date == 3 ? "rd" : "th").replace(/(^|[^a-z$])m/g, "$1" + (month + 1)).replace(/(^|[^a-z$])d/g, "$1" + date);
|
|
3246
|
+
return _formatDate(dateStr, format, this.settings);
|
|
3182
3247
|
}
|
|
3183
3248
|
formatTime(dateStr, format) {
|
|
3184
|
-
|
|
3185
|
-
if (dateStr === "" || dateStr == null || typeof dateStr === "object" && !dateStr.getMonth) return "";
|
|
3186
|
-
let dt = new Date(dateStr);
|
|
3187
|
-
if (this.isInt(dateStr)) dt = new Date(Number(dateStr));
|
|
3188
|
-
if (this.isTime(dateStr)) {
|
|
3189
|
-
const tmp = this.isTime(dateStr, true);
|
|
3190
|
-
dt = /* @__PURE__ */ new Date();
|
|
3191
|
-
dt.setHours(tmp.hours);
|
|
3192
|
-
dt.setMinutes(tmp.minutes);
|
|
3193
|
-
}
|
|
3194
|
-
if (String(dt) === "Invalid Date") return "";
|
|
3195
|
-
if (format == "h12") format = "hh:mi pm";
|
|
3196
|
-
let type = "am";
|
|
3197
|
-
let hour = dt.getHours();
|
|
3198
|
-
const h24 = dt.getHours();
|
|
3199
|
-
let min = dt.getMinutes();
|
|
3200
|
-
let sec = dt.getSeconds();
|
|
3201
|
-
if (min < 10) min = "0" + min;
|
|
3202
|
-
if (sec < 10) sec = "0" + sec;
|
|
3203
|
-
if (format.indexOf("am") !== -1 || format.indexOf("pm") !== -1) {
|
|
3204
|
-
if (hour >= 12) type = "pm";
|
|
3205
|
-
if (hour > 12) hour = hour - 12;
|
|
3206
|
-
if (hour === 0) hour = 12;
|
|
3207
|
-
}
|
|
3208
|
-
const hourStr = String(hour);
|
|
3209
|
-
const minStr = String(min);
|
|
3210
|
-
const secStr = String(sec);
|
|
3211
|
-
const h24Str = String(h24);
|
|
3212
|
-
return format.toLowerCase().replace("am", type).replace("pm", type).replace("hhh", Number(hour) < 10 ? "0" + hourStr : hourStr).replace("hh24", h24 < 10 ? "0" + h24Str : h24Str).replace("h24", h24Str).replace("hh", hourStr).replace("mm", minStr).replace("mi", minStr).replace("ss", secStr).replace(/(^|[^a-z$])h/g, "$1" + hourStr).replace(/(^|[^a-z$])m/g, "$1" + minStr).replace(/(^|[^a-z$])s/g, "$1" + secStr);
|
|
3249
|
+
return _formatTime(dateStr, format, this.settings);
|
|
3213
3250
|
}
|
|
3214
3251
|
formatDateTime(dateStr, format) {
|
|
3215
|
-
|
|
3216
|
-
if (dateStr === "" || dateStr == null || typeof dateStr === "object" && !dateStr.getMonth) return "";
|
|
3217
|
-
if (typeof format !== "string") {
|
|
3218
|
-
fmt = [this.settings.dateFormat, this.settings.timeFormat];
|
|
3219
|
-
} else {
|
|
3220
|
-
fmt = format.split("|");
|
|
3221
|
-
if (fmt[0] != null) fmt[0] = fmt[0].trim();
|
|
3222
|
-
fmt[1] = fmt.length > 1 ? (fmt[1] ?? "").trim() : this.settings.timeFormat;
|
|
3223
|
-
}
|
|
3224
|
-
if (fmt[1] === "h12") fmt[1] = "h:m pm";
|
|
3225
|
-
if (fmt[1] === "h24") fmt[1] = "h24:m";
|
|
3226
|
-
return this.formatDate(dateStr, fmt[0]) + " " + this.formatTime(dateStr, fmt[1]);
|
|
3252
|
+
return _formatDateTime(dateStr, format, this.settings);
|
|
3227
3253
|
}
|
|
3228
3254
|
stripSpaces(html) {
|
|
3229
3255
|
return stripSpaces(html);
|