#
        new Utils/Date()
    
    
    
        Extends moment.js with additional features.
Also provides a backwards compatibility layer for existing code; however,
this is deprecated and you are strongly advised not to use it.
     
    
    
    
    
    
    
    
    
    
    
    
    
    
        
    
    
    
    
    
     
    
    
    
        Classes
        
            - duration
 
            
        
    
     
    
    
    
        Methods
        
            
    
    
        #
        (static) compare(date1, date2) → {number}
    
    
    
        Performs a three-way comparison between two dates.
Compatible with Array.sort and similar functions.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        
        Description | 
    
    
    
    
        
            
                date1 | 
            
            
            
                
string
            
             | 
            
            
            The first date to compare.  | 
        
    
        
            
                date2 | 
            
            
            
                
string
            
             | 
            
            
            The second date to compare.  | 
        
    
    
     
    
    
    
    
    
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    Throws:
    
        
    
    
        if any of the given dates are invalid.
    
     
    
     
    
    Returns:
        
            
    The result of comparing date1 to date2:
-1 if date1 < date2 
0 if date1 = date2 
1 if date1 > date2 
 
    - 
        Type
    
 
    - 
        
number
    
 
            
     
        
            
    
    
    
    
        Formats JavaScript Date objects into date strings.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        
        Description | 
    
    
    
    
        
            
                date | 
            
            
            
                
Date
            
             | 
            
            
            The date to format.  | 
        
    
        
            
                format | 
            
            
            
                
string
            
             | 
            
            
            Date format string such as 'Y-m-d H:i:s'.  | 
        
    
    
     
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    
        
    
    
    
    
    
    Returns:
        
            
    The formatted date string.
 
    - 
        Type
    
 
    - 
        
string
    
 
            
     
        
            
    
    
        #
        (static) getRelativeTimeLabel(date) → {Object}
    
    
    
        Converts a Date object into a relative time.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        
        Description | 
    
    
    
    
        
            
                date | 
            
            
            
                
Date
            
             | 
            
            
            Date object to convert.  | 
        
    
    
     
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    
        
    
    
    
    
    
    Returns:
        
            
    Object containing relative time key string and value
suitable for passing to a Handlebars template.
 
    - 
        Type
    
 
    - 
        
Object
    
 
            
     
        
            
    
    
    
    
        Gets the date format preference for the given user.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        Attributes | 
        
        
        Default | 
        
        Description | 
    
    
    
    
        
            
                user | 
            
            
            
                
Data/Bean
|
Object
            
             | 
            
                
                
                    <optional> 
                
                
                
                 | 
            
            
                
                
                    Core.User
                
                 | 
            
            The user whose date format
you want.  | 
        
    
    
     
    
    
    
    
    
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    Returns:
        
            
    A format string for the user's preferred date format.
 
    - 
        Type
    
 
    - 
        
string
    
 
            
     
        
            
    
    
    
    
        Gets the time format preference for the given user.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        Attributes | 
        
        
        Default | 
        
        Description | 
    
    
    
    
        
            
                user | 
            
            
            
                
Data/Bean
|
Object
            
             | 
            
                
                
                    <optional> 
                
                
                
                 | 
            
            
                
                
                    Core.User
                
                 | 
            
            The user whose time format
you want.  | 
        
    
    
     
    
    
    
    
    
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    Returns:
        
            
    A format string for the user's preferred time format.
 
    - 
        Type
    
 
    - 
        
string
    
 
            
     
        
            
    
    
    
    
        Guesses the format of a date string.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        
        Description | 
    
    
    
    
        
            
                date | 
            
            
            
                
string
            
             | 
            
            
            A date string.  | 
        
    
    
     
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    
        
    
    
    
    
    
    Returns:
        
            
    A string encoding the date/time format used by
date, or false if date is invalid.
 
    - 
        Type
    
 
    - 
        
string
|
boolean
    
 
            
     
        
            
    
    
        #
        (static) isIso(val) → {boolean}
    
    
    
        Determines if a date string is in ISO 8601 format.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        
        Description | 
    
    
    
    
        
            
                val | 
            
            
            
                
string
            
             | 
            
            
            The date string to check.  | 
        
    
    
     
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    
        
    
    
    
    
    
    Returns:
        
            
    true if val is compliant with ISO 8601.
 
    - 
        Type
    
 
    - 
        
boolean
    
 
            
     
        
            
    
    
        #
        (static) parse(date, oldFormatopt) → {Date}
    
    
    
        Parses date strings into JavaScript Dates.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        Attributes | 
        
        
        Description | 
    
    
    
    
        
            
                date | 
            
            
            
                
string
            
             | 
            
                
                
                
                
                 | 
            
            
            The date string to parse.  | 
        
    
        
            
                oldFormat | 
            
            
            
                
string
            
             | 
            
                
                
                    <optional> 
                
                
                
                 | 
            
            
            Date format string. If not specified,
this function will guess the date format.  | 
        
    
    
     
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    
        
    
    
    
    
    
    Returns:
        
            
    A Date object corresponding to the given date.
 
    - 
        Type
    
 
    - 
        
Date
    
 
            
     
        
            
    
    
        #
        (static) parseDisplayDefault(displayDefault, nowopt) → {Date|undefined}
    
    
    
        Parses the display_default property which the server returns for
datetimecombo metadata, etc. (for example, if the user sets the default
in Studio).
Examples:
const DateManager = require('utils/date');
DateManager.parseDisplayDefault('+1 day&06:00pm');
DateManager.parseDisplayDefault('-1 day&06:00pm');
DateManager.parseDisplayDefault('+1 week&06:00pm');
DateManager.parseDisplayDefault('+1 month&06:00pm');
DateManager.parseDisplayDefault('+1 year&06:00pm');
DateManager.parseDisplayDefault('now&06:00pm');
DateManager.parseDisplayDefault('next monday&06:00pm');
DateManager.parseDisplayDefault('next friday&06:00pm');
DateManager.parseDisplayDefault('first of next month@06:00pm');
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        Attributes | 
        
        
        Default | 
        
        Description | 
    
    
    
    
        
            
                displayDefault | 
            
            
            
                
string
            
             | 
            
                
                
                
                
                 | 
            
            
                
                
                 | 
            
            The value of the display_default
property.  | 
        
    
        
            
                now | 
            
            
            
                
Date
            
             | 
            
                
                
                    <optional> 
                
                
                
                 | 
            
            
                
                
                    new Date()
                
                 | 
            
            An optional date to use as a point of
reference (since we essentially convert "+1 day", etc., to an
adjusted date). This is mainly for testing odd dates like adding a
month specifically to January 31, etc.  | 
        
    
    
     
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    
        
    
    
    
    
    
    Returns:
        
            
    The date created by evaluating displayDefault
relative to now.
 
    - 
        Type
    
 
    - 
        
Date
|
undefined
    
 
            
     
        
            
    
    
    
    
        Parses a date format string into each of its individual representations.
Supports only the options that are supported by the date.format
function.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        
        Description | 
    
    
    
    
        
            
                format | 
            
            
            
                
string
            
             | 
            
            
            A date format string such as 'Y-m-d H:i:s'.  | 
        
    
    
     
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    
        
    
    
    
    
    
    Returns:
        
            
    Object with properties representing each piece of a
format.
 
    - 
        Type
    
 
    - 
        
Object
    
 
            
     
        
            
    
    
        #
        (static) roundTime(date) → {Date}
    
    
    
        Rounds a date to the nearest 15 minutes.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        
        Description | 
    
    
    
    
        
            
                date | 
            
            
            
                
Date
            
             | 
            
            
            A date to round.  | 
        
    
    
     
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    
        
    
    
    
    
    
        
            
    
    
        #
        (static) stripIsoTimeDelimterAndTZ(value) → {string}
    
    
    
        Strips out the 'T' and either the 'Z' or +00:00 from a date string.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        
        Description | 
    
    
    
    
        
            
                value | 
            
            
            
                
string
            
             | 
            
            
            The date string to strip in ISO 8601 format.  | 
        
    
    
     
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    
        
    
    
    
    
    
    Returns:
        
            
    The result of removing the time delimiter and time zone
indicator from value.
 
    - 
        Type
    
 
    - 
        
string
    
 
            
     
        
            
    
    
    
    
        Converts a PHP date format string to its Bootstrap Datepicker equivalent.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        
        Description | 
    
    
    
    
        
            
                formatSpec | 
            
            
            
                
string
            
             | 
            
            
            The original SugarCRM (PHP) date format.  | 
        
    
    
     
    
    
    
    
    
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    Returns:
        
            
    Format spec passed in normalized for the Bootstrap
Datepicker widget. If falsy, returns empty string.
 
    - 
        Type
    
 
    - 
        
string
    
 
            
     
        
            
    
    
        #
        (static) toUTC(date) → {number}
    
    
    
        Converts the date from local time to UTC.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        
        Description | 
    
    
    
    
        
            
                date | 
            
            
            
                
Date
            
             | 
            
            
            A UTC date.  | 
        
    
    
     
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    
        
    
    
    
    
    
    Returns:
        
            
    The given date as milliseconds since the Unix epoch
in UTC.
 
    - 
        Type
    
 
    - 
        
number
    
 
            
     
        
            
    
    
        #
        (static) UTCtoLocalTime(date) → {Date}
    
    
    
        Converts a UTC date to a local time date.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        
        Description | 
    
    
    
    
        
            
                date | 
            
            
            
                
Date
            
             | 
            
            
            A UTC date.  | 
        
    
    
     
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    
        
    
    
    
    
    
    Returns:
        
            
    Date converted to local time.
 
    - 
        Type
    
 
    - 
        
Date
    
 
            
     
        
            
    
    
        #
        (static) UTCtoTimezone(date, offset) → {Date}
    
    
    
        Converts a UTC date to a date in the timezone represented by the offset.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        
        Description | 
    
    
    
    
        
            
                date | 
            
            
            
                
Date
            
             | 
            
            
            A UTC date.  | 
        
    
        
            
                offset | 
            
            
            
                
number
            
             | 
            
            
            The timezone's UTC offset in hours.  | 
        
    
    
     
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    
        
    
    
    
    
    
        
            
    
    
    
    
        Formats this date to a string according to the server date format and locale.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        Attributes | 
        
        
        Default | 
        
        Description | 
    
    
    
    
        
            
                dateOnly | 
            
            
            
                
boolean
            
             | 
            
                
                
                    <optional> 
                
                
                
                 | 
            
            
                
                
                    false
                
                 | 
            
            Pass true to only get the date.  | 
        
    
    
     
    
    
    
    
    
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    Returns:
        
            
    This date formatted according to the server date format.
 
    - 
        Type
    
 
    - 
        
string
    
 
            
     
        
            
    
    
    
    
        Formats this date to a string based on user preferences.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        Attributes | 
        
        
        Default | 
        
        Description | 
    
    
    
    
        
            
                dateOnly | 
            
            
            
                
boolean
            
             | 
            
                
                
                    <optional> 
                
                
                
                 | 
            
            
                
                
                    false
                
                 | 
            
            Pass true to only get the date.  | 
        
    
        
            
                user | 
            
            
            
                
Data/Bean
|
Object
            
             | 
            
                
                
                    <optional> 
                
                
                
                 | 
            
            
                
                
                    Core.User
                
                 | 
            
            The user bean or the
current logged in user object.  | 
        
    
    
     
    
    
    
    
    
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    Returns:
        
            
    The formatted date based on user's preference.
 
    - 
        Type
    
 
    - 
        
string
    
 
            
     
        
            
    
    
        #
        isBetween(startDate, endDate, inclusiveopt) → {boolean}
    
    
    
        Returns true if this date is between the given startDate and
endDate.
     
    
        Parameters:
        
    
    
        
        | Name | 
        
        Type | 
        
        Attributes | 
        
        
        Default | 
        
        Description | 
    
    
    
    
        
            
                startDate | 
            
            
            
                
string
            
             | 
            
                
                
                
                
                 | 
            
            
                
                
                 | 
            
            The start date of the period to test.  | 
        
    
        
            
                endDate | 
            
            
            
                
string
            
             | 
            
                
                
                
                
                 | 
            
            
                
                
                 | 
            
            The end date of the period to test.  | 
        
    
        
            
                inclusive | 
            
            
            
                
boolean
            
             | 
            
                
                
                    <optional> 
                
                
                
                 | 
            
            
                
                
                    true
                
                 | 
            
            If true, include startDate and
endDate in the range of acceptable dates.  | 
        
    
    
     
    
    
    
    
    
    
    
    
    
    
    
    
    
        
    
    
    
    
    
    Returns:
        
            
    true if this date is between startDate and endDate;
false otherwise.
 
    - 
        Type
    
 
    - 
        
boolean