aboutsummaryrefslogtreecommitdiffstats
path: root/library/moment/src/lib/create/date-from-array.js
blob: 349eebcc4f1b5614a8ec1a7aa113e34a746319ce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
export function createDate (y, m, d, h, M, s, ms) {
    //can't just apply() to create a date:
    //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply
    var date = new Date(y, m, d, h, M, s, ms);

    //the date constructor doesn't accept years < 1970
    if (y < 1970) {
        date.setFullYear(y);
    }
    return date;
}

export function createUTCDate (y) {
    var date = new Date(Date.UTC.apply(null, arguments));
    if (y < 1970) {
        date.setUTCFullYear(y);
    }
    return date;
}