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
Methods
- 
    <static> compare(date1, date2)
- 
    
    Performs a three-way comparison between two dates. Compatible with Array.sortand similar functions.Parameters:Name Type Description date1string The first date to compare. date2string The second date to compare. Throws:if any of the given dates are invalid. Returns:The result of comparing date1todate2:- -1if date1 < date2
- 0if date1 = date2
- 1if date1 > date2
 - Type
- number
 
- 
    <static> format(date, format)
- 
    
    Formats JavaScript Date objects into date strings. Parameters:Name Type Description dateDate The date to format. formatstring Date format string such as 'Y-m-d H:i:s'. - Deprecated:
- 
        - since 7.2.0.
 
 Returns:The formatted date string. - Type
- string
 
- 
    <static> getRelativeTimeLabel(date)
- 
    
    Converts a Date object into a relative time. Parameters:Name Type Description dateDate Date object to convert. - Deprecated:
- 
        - since 7.2.0.
 
 Returns:Object containing relative time key string and value suitable for passing to a Handlebars template. - Type
- Object
 
- 
    <static> getUserDateFormat( [user])
- 
    
    Gets the date format preference for the given user. Parameters:Name Type Argument Default Description userData/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
 
- 
    <static> getUserTimeFormat( [user])
- 
    
    Gets the time format preference for the given user. Parameters:Name Type Argument Default Description userData/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
 
- 
    <static> guessFormat(date)
- 
    
    Guesses the format of a date string. Parameters:Name Type Description datestring A date string. - Deprecated:
- 
        - since 7.2.0.
 
 Returns:A string encoding the date/time format used by date, orfalseifdateis invalid.- Type
- string | boolean
 
- 
    <static> isIso(val)
- 
    
    Determines if a date string is in ISO 8601 format. Parameters:Name Type Description valstring The date string to check. - Deprecated:
- 
        - since 7.2.0.
 
 Returns:trueifvalis compliant with ISO 8601.- Type
- boolean
 
- 
    <static> parse(date [, oldFormat])
- 
    
    Parses date strings into JavaScript Dates. Parameters:Name Type Argument Description datestring The date string to parse. oldFormatstring <optional> 
 Date format string. If not specified, this function will guess the date format. - Deprecated:
- 
        - since 7.2.0.
 
 Returns:A Date object corresponding to the given date.- Type
- Date
 
- 
    <static> parseDisplayDefault(displayDefault [, now])
- 
    
    Parses the display_defaultproperty 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 Argument Default Description displayDefaultstring The value of the display_defaultproperty.nowDate <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. - Deprecated:
- 
        - since 7.2.0.
 
 Returns:The date created by evaluating displayDefaultrelative tonow.- Type
- Date | undefined
 
- 
    <static> parseFormat(format)
- 
    
    Parses a date format string into each of its individual representations. Supports only the options that are supported by the date.formatfunction.Parameters:Name Type Description formatstring A date format string such as 'Y-m-d H:i:s'. - Deprecated:
- 
        - since 7.2.0.
 
 Returns:Object with properties representing each piece of a format. - Type
- Object
 
- 
    <static> roundTime(date)
- 
    
    Rounds a date to the nearest 15 minutes. Parameters:Name Type Description dateDate A date to round. - Deprecated:
- 
        - since 7.2.0.
 
 Returns:Rounded date. - Type
- Date
 
- 
    <static> stripIsoTimeDelimterAndTZ(value)
- 
    
    Strips out the 'T' and either the 'Z' or +00:00 from a date string. Parameters:Name Type Description valuestring The date string to strip in ISO 8601 format. - Deprecated:
- 
        - since 7.2.0.
 
 Returns:The result of removing the time delimiter and time zone indicator from value.- Type
- string
 
- 
    <static> toDatepickerFormat(formatSpec)
- 
    
    Converts a PHP date format string to its Bootstrap Datepicker equivalent. Parameters:Name Type Description formatSpecstring 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)
- 
    
    Converts the date from local time to UTC. Parameters:Name Type Description dateDate A UTC date. - Deprecated:
- 
        - since 7.2.0.
 
 Returns:The given dateas milliseconds since the Unix epoch in UTC.- Type
- number
 
- 
    <static> UTCtoLocalTime(date)
- 
    
    Converts a UTC date to a local time date. Parameters:Name Type Description dateDate A UTC date. - Deprecated:
- 
        - since 7.2.0.
 
 Returns:Date converted to local time. - Type
- Date
 
- 
    <static> UTCtoTimezone(date, offset)
- 
    
    Converts a UTC date to a date in the timezone represented by the offset. Parameters:Name Type Description dateDate A UTC date. offsetnumber The timezone's UTC offset in hours. - Deprecated:
- 
        - since 7.2.0.
 
 Returns:Converted date. - Type
- Date
 
- 
    formatServer( [dateOnly])
- 
    
    Formats this date to a string according to the server date format and locale. Parameters:Name Type Argument Default Description dateOnlyboolean <optional> 
 false Pass trueto only get the date.Returns:This date formatted according to the server date format. - Type
- string
 
- 
    formatUser( [dateOnly] [, user])
- 
    
    Formats this date to a string based on user preferences. Parameters:Name Type Argument Default Description dateOnlyboolean <optional> 
 false Pass trueto only get the date.userData/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 [, inclusive])
- 
    
    Returns trueif this date is between the givenstartDateandendDate.Parameters:Name Type Argument Default Description startDatestring The start date of the period to test. endDatestring The end date of the period to test. inclusiveboolean <optional> 
 true If true, includestartDateandendDatein the range of acceptable dates.Returns:trueif this date is betweenstartDateandendDate;falseotherwise.- Type
- boolean