UTCDate helper and new printing for Date objects SERVER-1299
This commit is contained in:
@@ -265,9 +265,35 @@ const StringData _jscode_raw_utils =
|
||||
"}\n"
|
||||
"\n"
|
||||
"Date.prototype.tojson = function(){\n"
|
||||
"return \"\\\"\" + this.toString() + \"\\\"\";\n"
|
||||
"var year = this.getUTCFullYear();\n"
|
||||
"var month = this.getUTCMonth() + 1; // js is stupid\n"
|
||||
"var date = this.getUTCDate();\n"
|
||||
"var hour = this.getUTCHours();\n"
|
||||
"var minute = this.getUTCMinutes();\n"
|
||||
"var sec = this.getUTCSeconds() + (this.getUTCMilliseconds()/1000);\n"
|
||||
"\n"
|
||||
"return 'UTCDate('+year+', '+month+', '+date+', '+hour+', '+minute+', '+sec+')';\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"UTCDate = function(year, month, date, hour, min, sec, ms){\n"
|
||||
"if (!year) return new Date();\n"
|
||||
"\n"
|
||||
"month = (month || 1) - 1; // js is stupid\n"
|
||||
"date = (date || 1);\n"
|
||||
"hour = (hour || 0);\n"
|
||||
"min = (min || 0);\n"
|
||||
"sec = (sec || 0);\n"
|
||||
"ms = (ms || 0);\n"
|
||||
"\n"
|
||||
"// support fractional seconds\n"
|
||||
"if (sec % 1){\n"
|
||||
"ms = Math.round((sec%1) * 1000)\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"return new Date(Date.UTC(year, month, date, hour, min, sec, ms));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"RegExp.prototype.tojson = RegExp.prototype.toString;\n"
|
||||
"\n"
|
||||
"Array.contains = function( a , x ){\n"
|
||||
|
||||
Reference in New Issue
Block a user