heyujie
2021-05-20 6ebdefb4a5b2be82a8c452c0bb4624f3d85a17b7
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
"use strict";
 
var isPrototype = require("../prototype/is");
 
var dateValueOf = Date.prototype.valueOf;
 
module.exports = function (value) {
    if (!value) return false;
 
    try {
        // Sanity check (reject objects which do not expose common Date interface)
        if (typeof value.getFullYear !== "function") return false;
        if (typeof value.getTimezoneOffset !== "function") return false;
        if (typeof value.setFullYear !== "function") return false;
 
        // Ensure its native Date object (has [[DateValue]] slot)
        dateValueOf.call(value);
    } catch (error) {
        return false;
    }
 
    // Ensure it hosts valid date
    if (isNaN(value)) return false;
 
    return !isPrototype(value);
};