/**
 * Create a formattable date.
 *
 */
var array = require('../array'),
    toArray = array.toArray;

exports = module.exports = function () {
    var s = this;
    var argArray = toArray(arguments);
    argArray.unshift(null);
    s._date = new (Function.prototype.bind.apply(Date, argArray));
    exports._dateFunctionNames.forEach(function (key) {
        if (!s._date[key]) {
            console.log('not exists', key);
        }
        s[key] = s._date[key].bind(s._date);
    });
    s.addDate = function (date) {
        s._date.setDate(s._date.getDate() + date);
        return s;
    };
    s.addMonth = function (month) {
        s._date.setMonth(s._date.getMonth() + month);
        return s;
    };
    s.addYear = function (year) {
        s._date.setFullYear(s.getFullYear() + year);
        return s;
    };
    var dateFormat = require('dateformat');
    s.format = function (format) {
        return dateFormat(s._date, format);
    }
};


exports._dateFunctionNames = [
    "getDate", "getDay", "getFullYear", "getHours", "getMilliseconds", "getMinutes", "getMonth", "getSeconds", "getTime", "getTimezoneOffset", "getUTCDate", "getUTCDay", "getUTCFullYear", "getUTCHours", "getUTCMilliseconds", "getUTCMinutes", "getUTCMonth", "getUTCSeconds", "setDate", "setFullYear", "setHours", "setMilliseconds", "setMinutes", "setMonth", "setSeconds", "setTime", "setUTCDate", "setUTCFullYear", "setUTCHours", "setUTCMilliseconds", "setUTCMinutes", "setUTCMonth", "setUTCSeconds", "toDateString", "toGMTString", "toUTCString", "toISOString", "toJSON", "toLocaleDateString", "toLocaleTimeString", "toLocaleString", "toString", "toTimeString", "toUTCString", "valueOf"
];
