// Licensed Materials - Property of IBM // // IBM Cognos Products: cogadmin // // (C) Copyright IBM Corp. 2005, 2011 // // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. // // dojo.provide("com.ibm.cognos.admin.utils.Datetime"); /* * Add a feature to JS navtive datetime object to provide a mean to construct a datetime object on the * format of yyyy-mm-ddThh:mm:ss or yyyy-mm-dd * @param datetime, string with format of yyyy-mm-ddThh:mm:ss or yyyy-mm-dd */ (function(){ dojo.declare("com.ibm.cognos.admin.utils.Datetime",null,{ constructor : function (datetime){ this.datetime = datetime; }, getObject : function (){ //if empty return the now datetime object if (!this.datetime) return new Date(); //if it's an date object already, just return it if (this.datetime instanceof Date) return this.datetime; //otherwise do the construction var aDatetime = this.datetime.split("T"), y = 0, m = 0, d = 0, h = 0, min = 0, s = 0; if (aDatetime[0]){ var aDate = aDatetime[0].split("-"); y = aDate[0]; m = aDate[1] - 1; d = aDate[2]; }; if (aDatetime[1]){ var aTime = aDatetime[1].split(":"); h = aTime[0]; min = aTime[1]; s = aTime[2].substr(0,2); } return (new Date(y,m,d,h,min,s)); }, getDateString : function (){ var o = this.getObject(); var month = o.getMonth() + 1 + ""; var day = o.getDate() + ""; return o.getFullYear()+'-'+((month.length == 1)?'0':'')+month+'-'+((day.length == 1)?'0':'')+day; }, getTimeString : function (){ var o = this.getObject(); var hour = o.getHours() + ""; var min = o.getMinutes() + ""; var sec = o.getSeconds() + ""; return ((hour.length == 1)?'0':'')+hour+':'+((min.length == 1)?'0':'')+min+':'+((sec.length == 1)?'0':'')+sec; }, getDateTimeString : function (){ return this.getDateString() + 'T' + this.getTimeString(); }, isToday : function (){ var today = new com.ibm.cognos.admin.utils.Datetime(new Date()); return today.getDateString() == this.getDateString(); } }) })();