UTCDate helper and new printing for Date objects SERVER-1299

This commit is contained in:
Mathias Stearn
2010-08-18 20:19:47 -04:00
parent 8360e22198
commit bb5c545e79
2 changed files with 53 additions and 2 deletions

View File

@@ -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"