Options
All
  • Public
  • Public/Protected
  • All
Menu

Module Date

JMap.Util.Date

Here you'll find all JMap date utility methods

Index

Functions

add

  • JMap.Util.Date.add

    Returns a date, that is the given date plus the given amount of unit.

    It's safe, the given date is not changed.

    Possible time units are : "seconds" | "minutes" | "hours" | "days" | "weeks" | "months" |"years"

    throws
    example
    
    // returns the date 2 days in the future
    JMap.Util.Date.add(new Date(), 2, "days")
    
    // returns the date 2 seconds in the future
    JMap.Util.Date.add(new Date(), 2, "seconds")

    Parameters

    Returns Date

format

  • JMap.Util.Date.format

    Returns a formatted string from a date.

    throws

    if date is not a Date object, or ISO string, or timestamp number

    example
    
    // returns the current date as a string, according to the current user locale
    JMap.Util.Date.format(new Date())
    
    // returns the current date as a string, with time, according to the current user locale
    JMap.Util.Date.format(new Date(), {
     displayTime: true
    })

    Parameters

    Returns string

formatDistanceToNow

  • JMap.Util.Date.formatDistanceToNow

    Returns in the user's locale language, the time that will pass, or passed from now for the given date.

    throws

    if date is not a Date object, or ISO string, or timestamp number

    example
    
    // returns in the user's locale language, the time that will pass, or passed from now for the given date
    JMap.Util.Date.formatDistanceToNow(new Date())

    Parameters

    Returns string

getDate

  • JMap.Util.Date.getDate

    Returns the date for the given input.

    example
    
    // returns a date object for the given timestamp
    JMap.Util.Date.getDate(1631879544000)
    
    // returns a date object for the given ISO string
    JMap.Util.Date.getDate("2012-09-27")

    Parameters

    • date: JDateLike

      the date as a string, number, or Date

    Returns Date

getDateFnsLocale

  • getDateFnsLocale(displayTime?: undefined | false | true): any
  • JMap.Util.Date.getDateFnsLocale

    Returns the format for date-fns library.

    example
    
    // returns the format for date-fns library without datetime
    JMap.Util.Date.getDateFnsLocale()
    
    // returns the format for date-fns library without datetime
    JMap.Util.Date.getDateFnsLocale(true)

    Parameters

    • Optional displayTime: undefined | false | true

      true to return the format including the time

    Returns any

getDateFromISOString

  • getDateFromISOString(isoDate: string): Date
  • JMap.Util.Date.getDateFromISOString

    Returns a date corresponding to the given ISO-8601 date string.

    throws
    example
    
    // returns a date corresponding to the given ISO-8601 date string.
    JMap.Util.Date.getDateFromISOString()

    Parameters

    • isoDate: string

      IS-8601 string date

    Returns Date

is12HoursTimeFormat

  • is12HoursTimeFormat(): boolean
  • JMap.Util.Date.is12HoursTimeFormat

    Returns true if the current user locale use AM-PM format, else false.

    example
    
    // returns true if the current user locale use AM-PM format, else false
    JMap.Util.Date.is12HoursTimeFormat()

    Returns boolean

isAfter

  • isAfter(date1: JDateLike, date2: JDateLike, checkTime?: undefined | false | true): boolean
  • JMap.Util.Date.isAfter

    Returns true if the first date is after the second date.

    throws

    if dates are not Date object, or ISO string, or timestamp number

    example
    
    // returns in the user's locale language, the time that will pass, or passed from now for the given date
    const firstDate = new Date()
    setTimeout(() => {
     const secondDate = new Date()
     // will return false (time is not checked)
     JMap.Util.Date.isAfter(secondDate, firstDate)
    
     // will return true (because also check the time)
     JMap.Util.Date.isAfter(secondDate, firstDate, true)
    }, 1000)

    Parameters

    • date1: JDateLike

      Date object, or ISO string, or timestamp number

    • date2: JDateLike

      Date object, or ISO string, or timestamp number

    • Optional checkTime: undefined | false | true

      if true will also check the date time, else check only the date

    Returns boolean

isBefore

  • isBefore(date1: JDateLike, date2: JDateLike, checkTime?: undefined | false | true): boolean
  • JMap.Util.Date.isBefore

    Returns true if the first date is before the second date.

    throws

    if dates are not Date object, or ISO string, or timestamp number

    example
    
    // returns in the user's locale language, the time that will pass, or passed from now for the given date
    const firstDate = new Date()
    setTimeout(() => {
     const secondDate = new Date()
     // will return false
     JMap.Util.Date.isBefore(firstDate, secondDate)
    
     // will return true (because also check the time)
     JMap.Util.Date.isBefore(firstDate, secondDate, true)
    }, 1000)

    Parameters

    • date1: JDateLike

      Date object, or ISO string, or timestamp number

    • date2: JDateLike

      Date object, or ISO string, or timestamp number

    • Optional checkTime: undefined | false | true

      if true will also check the date time, else check only the date

    Returns boolean

substract

  • JMap.Util.Date.substract

    Returns a date, that is the given date minus the given amount of unit.

    It's safe, the given date is not changed.

    Possible time units are : "seconds" | "minutes" | "hours" | "days" | "weeks" | "months" |"years"

    throws
    example
    
    // returns the date 2 days in the past
    JMap.Util.Date.substract(new Date(), 2, "days")
    
    // returns the date 2 seconds in the past
    JMap.Util.Date.substract(new Date(), 2, "seconds")

    Parameters

    Returns Date