﻿/****************************************
*               Date
*****************************************/

/// <summary>
/// Gets the unique id from the data instance
/// </summary>
Date.prototype.getUniqueId = function() 
{
    var uniqueId = '';
    
    uniqueId += this.getDate();
    uniqueId += this.getMonth();
    uniqueId += this.getFullYear();
    
    return uniqueId;
} // getUniqueId

/// <summary>
/// Checks if the given date belongs to this instance
/// month and year
/// </summary>
Date.prototype.sameMonthAndYear = function( dateToCompare ) 
{
    return this.getMonth() == dateToCompare.getMonth() && this.getFullYear() == dateToCompare.getFullYear();
} // sameMonthAndYear

/// <summary>
/// Clone and returns this instance
/// </summary>
Date.prototype.clone = function() 
{
    var date = new Date
                (
                    this.getFullYear(),
                    this.getMonth(),
                    this.getDate(),
                    this.getHours(),
                    this.getMinutes(),
                    this.getSeconds(),
                    this.getMilliseconds()
                );
    
    return date;
} // clone

/// <summary>
/// Check if the given date time is equal to this instance
/// </summary>
Date.prototype.equals = function( dateTimeObject ) 
{
    return this.getFullYear() == dateTimeObject.getFullYear() &&
           this.getMonth() == dateTimeObject.getMonth() &&
           this.getDate() == dateTimeObject.getDate();
} // equals

/// <summary>
/// Returns the date time string representing this instance
/// </summary>
Date.prototype.toCustomString = function() 
{
    var dateString = '';
    
    dateString += this.getFullYear();
    dateString += ( ( (this.getMonth() + 1) < 10 ) ? '0': '' ) + (this.getMonth() + 1);
    dateString += ( ( this.getDate() < 10 ) ? '0': '' ) + this.getDate();
    dateString += ( ( this.getHours() < 10 ) ? '0': '' ) + this.getHours();
    dateString += ( ( this.getMinutes() < 10 ) ? '0': '' ) + this.getMinutes();
    dateString += ( ( this.getSeconds() < 10 ) ? '0': '' ) + this.getSeconds();
    
    return dateString;
} // toCustomString

/// <summary>
/// Set the minimun time (hours, minutes, seconds and milliseconds) as possible
/// </summary>
Date.prototype.setMinTime = function() 
{
    this.setHours( 0 );
    this.setMinutes( 0 );
    this.setSeconds( 0 );
    this.setMilliseconds( 0 );
} // setMinTime

/// <summary>
/// Set the maximun time (hours, minutes, seconds and milliseconds) as possible
/// </summary>
Date.prototype.setMaxTime = function() 
{
    this.setHours( 23 );
    this.setMinutes( 59 );
    this.setSeconds( 59 );
    this.setMilliseconds( 999 );
} // setMaxTime