@aqzhyi/dayjs
Advanced tools
Comparing version 0.8.0 to 0.9.0
# @aqzhyi/dayjs | ||
## 0.9.0 | ||
### Minor Changes | ||
- d3de391: 依據 eslint 修正了程式碼 | ||
## 0.8.0 | ||
@@ -4,0 +10,0 @@ |
import configs from '@aqzhyi/eslint-config' | ||
export default [...configs] | ||
const our = { | ||
ignores: ['esm/**/*', 'dist/**/*', 'src/typings'], | ||
} | ||
export default [...configs, our] |
186
esm/index.js
@@ -28,6 +28,6 @@ var _0 = Object.create | ||
k = 'week', | ||
S = 'month', | ||
T = 'month', | ||
X = 'quarter', | ||
C = 'year', | ||
T = 'date', | ||
S = 'date', | ||
U = 'Invalid Date', | ||
@@ -62,5 +62,5 @@ F = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, | ||
var G = 12 * (E.year() - V.year()) + (E.month() - V.month()), | ||
J = V.clone().add(G, S), | ||
J = V.clone().add(G, T), | ||
P = E - J < 0, | ||
Q = V.clone().add(G + (P ? -1 : 1), S) | ||
Q = V.clone().add(G + (P ? -1 : 1), T) | ||
return +(-(G + (E - J) / (P ? J - Q : Q - J)) || 0) | ||
@@ -73,3 +73,3 @@ }, | ||
return ( | ||
{ M: S, y: C, w: k, d: K, D: T, h: Z, m: I, s: q, ms: R, Q: X }[L] || | ||
{ M: T, y: C, w: k, d: K, D: S, h: Z, m: I, s: q, ms: R, Q: X }[L] || | ||
String(L || '') | ||
@@ -87,5 +87,5 @@ .toLowerCase() | ||
O[B] = w | ||
var A = '$isDayjsObject', | ||
var j = '$isDayjsObject', | ||
_ = function (L) { | ||
return L instanceof n || !(!L || !L[A]) | ||
return L instanceof n || !(!L || !L[j]) | ||
}, | ||
@@ -119,3 +119,3 @@ b = function L(V, E, G) { | ||
function L(E) { | ||
;(this.$L = b(E.locale, null, !0)), this.parse(E), (this.$x = this.$x || E.x || {}), (this[A] = !0) | ||
;(this.$L = b(E.locale, null, !0)), this.parse(E), (this.$x = this.$x || E.x || {}), (this[j] = !0) | ||
} | ||
@@ -192,3 +192,3 @@ var V = L.prototype | ||
M = this.$W, | ||
j = this.$M, | ||
A = this.$M, | ||
h = this.$D, | ||
@@ -199,10 +199,10 @@ m = 'set' + (this.$u ? 'UTC' : '') | ||
return P ? D(1, 0) : D(31, 11) | ||
case S: | ||
return P ? D(1, j) : D(0, j + 1) | ||
case T: | ||
return P ? D(1, A) : D(0, A + 1) | ||
case k: | ||
var d = this.$locale().weekStart || 0, | ||
o = (M < d ? M + 7 : M) - d | ||
return D(P ? h - o : h + (6 - o), j) | ||
return D(P ? h - o : h + (6 - o), A) | ||
case K: | ||
case T: | ||
case S: | ||
return c(m + 'Hours', 0) | ||
@@ -228,4 +228,4 @@ case Z: | ||
(J[K] = Q + 'Date'), | ||
(J[T] = Q + 'Date'), | ||
(J[S] = Q + 'Month'), | ||
(J[S] = Q + 'Date'), | ||
(J[T] = Q + 'Month'), | ||
(J[C] = Q + 'FullYear'), | ||
@@ -238,5 +238,5 @@ (J[Z] = Q + 'Hours'), | ||
c = P === K ? this.$D + (G - this.$W) : G | ||
if (P === S || P === C) { | ||
var M = this.clone().set(T, 1) | ||
M.$d[D](c), M.init(), (this.$d = M.set(T, Math.min(this.$D, M.daysInMonth())).$d) | ||
if (P === T || P === C) { | ||
var M = this.clone().set(S, 1) | ||
M.$d[D](c), M.init(), (this.$d = M.set(S, Math.min(this.$D, M.daysInMonth())).$d) | ||
} else D && this.$d[D](c) | ||
@@ -256,7 +256,7 @@ return this.init(), this | ||
var Q = z.p(G), | ||
D = function (j) { | ||
D = function (A) { | ||
var h = v(P) | ||
return z.w(h.date(h.date() + Math.round(j * E)), P) | ||
return z.w(h.date(h.date() + Math.round(A * E)), P) | ||
} | ||
if (Q === S) return this.set(S, this.$M + E) | ||
if (Q === T) return this.set(T, this.$M + E) | ||
if (Q === C) return this.set(C, this.$y + E) | ||
@@ -281,3 +281,3 @@ if (Q === K) return D(1) | ||
M = this.$M, | ||
j = J.weekdays, | ||
A = J.weekdays, | ||
h = J.months, | ||
@@ -321,7 +321,7 @@ m = J.meridiem, | ||
case 'dd': | ||
return d(J.weekdaysMin, G.$W, j, 2) | ||
return d(J.weekdaysMin, G.$W, A, 2) | ||
case 'ddd': | ||
return d(J.weekdaysShort, G.$W, j, 3) | ||
return d(J.weekdaysShort, G.$W, A, 3) | ||
case 'dddd': | ||
return j[G.$W] | ||
return A[G.$W] | ||
case 'H': | ||
@@ -367,3 +367,3 @@ return String(D) | ||
M = (c.utcOffset() - this.utcOffset()) * H, | ||
j = this - c, | ||
A = this - c, | ||
h = function () { | ||
@@ -376,3 +376,3 @@ return z.m(Q, c) | ||
break | ||
case S: | ||
case T: | ||
P = h() | ||
@@ -384,18 +384,18 @@ break | ||
case k: | ||
P = (j - M) / 604800000 | ||
P = (A - M) / 604800000 | ||
break | ||
case K: | ||
P = (j - M) / 86400000 | ||
P = (A - M) / 86400000 | ||
break | ||
case Z: | ||
P = j / W | ||
P = A / W | ||
break | ||
case I: | ||
P = j / H | ||
P = A / H | ||
break | ||
case q: | ||
P = j / Y | ||
P = A / Y | ||
break | ||
default: | ||
P = j | ||
P = A | ||
} | ||
@@ -405,3 +405,3 @@ return J ? P : z.a(P) | ||
(V.daysInMonth = function () { | ||
return this.endOf(S).$D | ||
return this.endOf(T).$D | ||
}), | ||
@@ -444,5 +444,5 @@ (V.$locale = function () { | ||
['$W', K], | ||
['$M', S], | ||
['$M', T], | ||
['$y', C], | ||
['$D', T], | ||
['$D', S], | ||
].forEach(function (L) { | ||
@@ -557,7 +557,7 @@ W0[L[1]] = function (V) { | ||
k = W(q), | ||
S = (Z = Z || '()')[0] === '(', | ||
T = (Z = Z || '()')[0] === '(', | ||
X = Z[1] === ')' | ||
return ( | ||
((S ? this.isAfter(K, I) : !this.isBefore(K, I)) && (X ? this.isBefore(k, I) : !this.isAfter(k, I))) || | ||
((S ? this.isBefore(K, I) : !this.isAfter(K, I)) && (X ? this.isAfter(k, I) : !this.isBefore(k, I))) | ||
((T ? this.isAfter(K, I) : !this.isBefore(K, I)) && (X ? this.isBefore(k, I) : !this.isAfter(k, I))) || | ||
((T ? this.isBefore(K, I) : !this.isAfter(K, I)) && (X ? this.isAfter(k, I) : !this.isBefore(k, I))) | ||
) | ||
@@ -583,3 +583,3 @@ } | ||
}) | ||
var S0 = l((Y0, Z0) => { | ||
var T0 = l((Y0, Z0) => { | ||
;(function (Y, H) { | ||
@@ -599,3 +599,3 @@ typeof Y0 == 'object' && typeof Z0 != 'undefined' | ||
}) | ||
var T0 = l((q0, G0) => { | ||
var S0 = l((q0, G0) => { | ||
;(function (Y, H) { | ||
@@ -626,12 +626,12 @@ typeof q0 == 'object' && typeof G0 != 'undefined' | ||
} | ||
function I(K, k, S, X) { | ||
return R.fromToBase(K, k, S, X) | ||
function I(K, k, T, X) { | ||
return R.fromToBase(K, k, T, X) | ||
} | ||
;(W.en.relativeTime = q), | ||
(R.fromToBase = function (K, k, S, X, C) { | ||
(R.fromToBase = function (K, k, T, X, C) { | ||
for ( | ||
var T, | ||
var S, | ||
U, | ||
F, | ||
x = S.$locale().relativeTime || q, | ||
x = T.$locale().relativeTime || q, | ||
w = Y.thresholds || [ | ||
@@ -656,8 +656,8 @@ { l: 's', r: 44, d: 'second' }, | ||
var B = w[$] | ||
B.d && (T = X ? W(K).diff(S, B.d, !0) : S.diff(K, B.d, !0)) | ||
var O = (Y.rounding || Math.round)(Math.abs(T)) | ||
if (((F = T > 0), O <= B.r || !B.r)) { | ||
B.d && (S = X ? W(K).diff(T, B.d, !0) : T.diff(K, B.d, !0)) | ||
var O = (Y.rounding || Math.round)(Math.abs(S)) | ||
if (((F = S > 0), O <= B.r || !B.r)) { | ||
O <= 1 && $ > 0 && (B = w[$ - 1]) | ||
var A = x[B.l] | ||
C && (O = C('' + O)), (U = typeof A == 'string' ? A.replace('%d', O) : A(O, k, B.l, F)) | ||
var j = x[B.l] | ||
C && (O = C('' + O)), (U = typeof j == 'string' ? j.replace('%d', O) : j(O, k, B.l, F)) | ||
break | ||
@@ -700,4 +700,4 @@ } | ||
var I, | ||
Z = function (X, C, T) { | ||
T === void 0 && (T = {}) | ||
Z = function (X, C, S) { | ||
S === void 0 && (S = {}) | ||
var U = new Date(X), | ||
@@ -725,8 +725,8 @@ F = (function (x, w) { | ||
) | ||
})(C, T) | ||
})(C, S) | ||
return F.formatToParts(U) | ||
}, | ||
K = function (X, C) { | ||
for (var T = Z(X, C), U = [], F = 0; F < T.length; F += 1) { | ||
var x = T[F], | ||
for (var S = Z(X, C), U = [], F = 0; F < S.length; F += 1) { | ||
var x = S[F], | ||
w = x.type, | ||
@@ -739,5 +739,5 @@ N = x.value, | ||
O = B === 24 ? 0 : B, | ||
A = U[0] + '-' + U[1] + '-' + U[2] + ' ' + O + ':' + U[4] + ':' + U[5] + ':000', | ||
j = U[0] + '-' + U[1] + '-' + U[2] + ' ' + O + ':' + U[4] + ':' + U[5] + ':000', | ||
_ = +X | ||
return (q.utc(A).valueOf() - (_ -= _ % 1000)) / 60000 | ||
return (q.utc(j).valueOf() - (_ -= _ % 1000)) / 60000 | ||
}, | ||
@@ -747,3 +747,3 @@ k = R.prototype | ||
X === void 0 && (X = I) | ||
var T = this.utcOffset(), | ||
var S = this.utcOffset(), | ||
U = this.toDate(), | ||
@@ -757,3 +757,3 @@ F = U.toLocaleString('en-US', { timeZone: X }), | ||
var N = w.utcOffset() | ||
w = w.add(T - N, 'minute') | ||
w = w.add(S - N, 'minute') | ||
} | ||
@@ -764,23 +764,23 @@ return (w.$x.$timezone = X), w | ||
var C = this.$x.$timezone || q.tz.guess(), | ||
T = Z(this.valueOf(), C, { timeZoneName: X }).find(function (U) { | ||
S = Z(this.valueOf(), C, { timeZoneName: X }).find(function (U) { | ||
return U.type.toLowerCase() === 'timezonename' | ||
}) | ||
return T && T.value | ||
return S && S.value | ||
}) | ||
var S = k.startOf | ||
var T = k.startOf | ||
;(k.startOf = function (X, C) { | ||
if (!this.$x || !this.$x.$timezone) return S.call(this, X, C) | ||
var T = q(this.format('YYYY-MM-DD HH:mm:ss:SSS'), { locale: this.$L }) | ||
return S.call(T, X, C).tz(this.$x.$timezone, !0) | ||
if (!this.$x || !this.$x.$timezone) return T.call(this, X, C) | ||
var S = q(this.format('YYYY-MM-DD HH:mm:ss:SSS'), { locale: this.$L }) | ||
return T.call(S, X, C).tz(this.$x.$timezone, !0) | ||
}), | ||
(q.tz = function (X, C, T) { | ||
var U = T && C, | ||
F = T || C || I, | ||
(q.tz = function (X, C, S) { | ||
var U = S && C, | ||
F = S || C || I, | ||
x = K(+q(), F) | ||
if (typeof X != 'string') return q(X).tz(F) | ||
var w = (function (O, A, _) { | ||
var b = O - 60 * A * 1000, | ||
var w = (function (O, j, _) { | ||
var b = O - 60 * j * 1000, | ||
v = K(b, _) | ||
if (A === v) return [b, A] | ||
var z = K((b -= 60 * (v - A) * 1000), _) | ||
if (j === v) return [b, j] | ||
var z = K((b -= 60 * (v - j) * 1000), _) | ||
return v === z ? [b, v] : [O - 60 * Math.min(v, z) * 1000, Math.max(v, z)] | ||
@@ -844,6 +844,6 @@ })(q.utc(X, U).valueOf(), x, F), | ||
} | ||
var S = Z.utcOffset | ||
var T = Z.utcOffset | ||
Z.utcOffset = function (U, F) { | ||
var x = this.$utils().u | ||
if (x(U)) return this.$u ? 0 : x(this.$offset) ? S.call(this) : this.$offset | ||
if (x(U)) return this.$u ? 0 : x(this.$offset) ? T.call(this) : this.$offset | ||
if ( | ||
@@ -855,5 +855,5 @@ typeof U == 'string' && | ||
if (!O) return null | ||
var A = ('' + O[0]).match(W) || ['-', 0, 0], | ||
_ = A[0], | ||
b = 60 * +A[1] + +A[2] | ||
var j = ('' + O[0]).match(W) || ['-', 0, 0], | ||
_ = j[0], | ||
b = 60 * +j[1] + +j[2] | ||
return b === 0 ? 0 : _ === '+' ? b : -b | ||
@@ -897,8 +897,8 @@ })(U)), | ||
} | ||
var T = Z.diff | ||
var S = Z.diff | ||
Z.diff = function (U, F, x) { | ||
if (U && this.$u === U.$u) return T.call(this, U, F, x) | ||
if (U && this.$u === U.$u) return S.call(this, U, F, x) | ||
var w = this.local(), | ||
N = I(U).local() | ||
return T.call(w, N, F, x) | ||
return S.call(w, N, F, x) | ||
} | ||
@@ -930,7 +930,7 @@ } | ||
x0 = f(F0(), 1), | ||
c0 = f(S0(), 1), | ||
$0 = f(T0(), 1), | ||
c0 = f(T0(), 1), | ||
$0 = f(S0(), 1), | ||
M0 = f(B0(), 1), | ||
A0 = f(C0(), 1), | ||
j0 = f(w0(), 1) | ||
j0 = f(C0(), 1), | ||
A0 = f(w0(), 1) | ||
var D0 = (Y, H, W) => { | ||
@@ -950,7 +950,7 @@ ;(H.prototype.formatDate = function () { | ||
k = 0, | ||
S = 0 | ||
if (Z >= 24) (Z = 23), (K = 59), (k = 59), (S = 59) | ||
else if (Z <= -1) (Z = 0), (K = 0), (k = 0), (S = 0) | ||
if (K >= 60) (K = 59), (k = 59), (S = 59) | ||
return this.startOf('days').set('hours', Z).set('minutes', K).set('seconds', k).set('milliseconds', S) | ||
T = 0 | ||
if (Z >= 24) (Z = 23), (K = 59), (k = 59), (T = 59) | ||
else if (Z <= -1) (Z = 0), (K = 0), (k = 0), (T = 0) | ||
if (K >= 60) (K = 59), (k = 59), (T = 59) | ||
return this.startOf('days').set('hours', Z).set('minutes', K).set('seconds', k).set('milliseconds', T) | ||
}, | ||
@@ -985,5 +985,5 @@ q = function (I) { | ||
g.default.extend($0.default) | ||
g.default.extend(A0.default) | ||
g.default.extend(O0.default) | ||
g.default.extend(j0.default) | ||
g.default.extend(O0.default) | ||
g.default.extend(A0.default) | ||
g.default.extend(M0.default) | ||
@@ -997,2 +997,2 @@ g.default.extend(x0.default) | ||
//# debugId=69EAF85F757BECD064756e2164756e21 | ||
//# debugId=0C003EC36421E55564756e2164756e21 |
{ | ||
"name": "@aqzhyi/dayjs", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"private": false, | ||
@@ -34,3 +34,3 @@ "keywords": [ | ||
"typescript": "^5.2.2", | ||
"@aqzhyi/eslint-config": "^0.4.0", | ||
"@aqzhyi/eslint-config": "^0.5.0", | ||
"@aqzhyi/tsconfig": "^0.5.0" | ||
@@ -40,3 +40,3 @@ }, | ||
"build": "bun build ./src/index.ts --outdir ./esm --target browser --format esm --splitting --sourcemap=external --minify", | ||
"lint": "eslint --color ./", | ||
"lint": "eslint --color ./ --quiet", | ||
"test": "jest --coverage", | ||
@@ -43,0 +43,0 @@ "test:w": "jest --watch", |
import { dayjs } from '.' | ||
let nowYYYYMMDD = `2024-01-01` | ||
const nowYYYYMMDD = `2024-01-01` | ||
let now = dayjs(`${nowYYYYMMDD} 00:00:00`) | ||
let nowUnix10 = 1704038400 | ||
let nowUnix13 = 1704038400000 | ||
const nowUnix10 = 1704038400 | ||
const nowUnix13 = 1704038400000 | ||
@@ -12,3 +12,3 @@ beforeEach(() => { | ||
test('.time() 返回包含到豪秒等級的 13位數 timestamp', () => { | ||
it('.time() 返回包含到豪秒等級的 13位數 timestamp', () => { | ||
expect(now.time()).toBe(nowUnix13) | ||
@@ -19,3 +19,3 @@ expect(now.unix()).toBe(nowUnix10) | ||
test('.format**()', () => { | ||
it('.format**()', () => { | ||
expect(now.formatDate()).toMatch(`${nowYYYYMMDD.replaceAll('-', '/')}`) | ||
@@ -26,10 +26,10 @@ expect(now.formatDateTime()).toMatch(`${nowYYYYMMDD.replaceAll('-', '/')} 00:00`) | ||
test('.setTime(:any)', () => { | ||
it('.setTime(:any)', () => { | ||
expect(now.setTime('i dont care').format()).toMatch(`Invalid Date`) | ||
// @ts-expect-error | ||
expect(now.setTime(function noop() {}).format()).toMatch(`Invalid Date`) | ||
expect(now.setTime(() => {}).format()).toMatch(`Invalid Date`) | ||
}) | ||
test('.setTime(:number)', () => { | ||
it('.setTime(:number)', () => { | ||
expect(now.setTime(-1).format()).toMatch(`${nowYYYYMMDD}T00:00:00`) | ||
@@ -48,3 +48,3 @@ expect(now.setTime(0).format()).toMatch(`${nowYYYYMMDD}T00:00:00`) | ||
test('.setTime(:string)', () => { | ||
it('.setTime(:string)', () => { | ||
expect(now.setTime('i am invalid string').format()).toBe(`Invalid Date`) | ||
@@ -81,3 +81,3 @@ | ||
test('dayjs(:number) 接受參數為 10位數字(處理誤植) 或 13位數字 或 16位數字(處理誤植)', () => { | ||
it('dayjs(:number) 接受參數為 10位數字(處理誤植) 或 13位數字 或 16位數字(處理誤植)', () => { | ||
const unix10 = 1704038400 | ||
@@ -93,3 +93,3 @@ const toBeTimeString = `2024/01/01 00:00:00` | ||
test('dayjs(:string) 接受參數為 10位數字(處理誤植) 或 13位數字 或 16位數字(處理誤植)', () => { | ||
it('dayjs(:string) 接受參數為 10位數字(處理誤植) 或 13位數字 或 16位數字(處理誤植)', () => { | ||
const unix10 = 1704038400 | ||
@@ -105,3 +105,3 @@ const toBeTimeString = `2024/01/01 00:00:00` | ||
test('dayjs(:string) 接受參數為 含有下劃線、或者 e 符號的字串型態的數字', () => { | ||
it('dayjs(:string) 接受參數為 含有下劃線、或者 e 符號的字串型態的數字', () => { | ||
const toBeTimeString = `2024/01/01 00:00:00` | ||
@@ -108,0 +108,0 @@ |
@@ -1,2 +0,2 @@ | ||
import dayjs from 'dayjs' | ||
import type dayjs from 'dayjs' | ||
@@ -3,0 +3,0 @@ declare module 'dayjs' { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
200956
1841