-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.dayjs.js
32 lines (29 loc) · 1.01 KB
/
jquery.dayjs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(function (root, factory) {
if (typeof define === "function" && define.amd) {
define(["dayjs"], factory);
} else if (typeof module === "object" && module.exports) {
module.exports = factory(require("dayjs"));
} else {
root["mu-jquery-dayjs/jquery.dayjs"] = factory(root["dayjs"]);
}
})(this, function (dayjs) {
var re = /^(isSame|isBefore|isAfter)(?:(?:\=(.+))|(?:([\+\-]\d+)(years|months|days|minutes|seconds)))/;
function getDate(matches) {
return matches[2]
? dayjs(matches[2])
: dayjs().add(parseInt(matches[3]), matches[4]);
}
return function ($) {
return $.expr.createPseudo
? $.expr.createPseudo(function (match) {
var matches = re.exec(match);
return function (element) {
return matches && dayjs($(element).val())[matches[1]](getDate(matches));
}
})
: function (element, index, match) {
var matches = re.exec(match);
return matches && dayjs($(element).val())[matches[1]](getDate(matches));
};
}
});