Class DateAdapter


  • public final class DateAdapter
    extends Object
    Maps a date adapter provided by CHART.JS to manage time series.
    It provides a set of methods to manage, parse and format dates and times.
    Author:
    Andrea "Stock" Stocchero
    • Constructor Detail

      • DateAdapter

        public DateAdapter()
        Creates a date adapter without any options.
      • DateAdapter

        public DateAdapter​(DateAdapterOptions options)
        Creates a date adapter using the options passed as argument.
        Parameters:
        options - date adapter options
    • Method Detail

      • getId

        public String getId()
        Returns the date adapter id.
        Returns:
        the date adapter id
      • getFormats

        public DateAdapterFormats getFormats()
        Returns the provided default formats.
        Returns:
        the provided default formats
      • getOptions

        public DateAdapterOptions getOptions()
        Returns the options used to configure the date adapter.
        Returns:
        the options used to configure the date adapter
      • parse

        public Date parse​(String time,
                          String format)
        Parses the given value and return the associated date.
        Parameters:
        time - the value to parse (usually comes from the data)
        format - the expected data format
        Returns:
        number date representation or null
      • format

        public String format​(long time,
                             String format)
        Returns the formatted date in the specified format for a given timestamp.
        Parameters:
        time - the timestamp to format
        format - the date/time token
        Returns:
        a date time string representation
      • format

        public String format​(long time,
                             TimeUnit unit)
        Returns the formatted date in the specified format for a given timestamp, using the default format related to time unit.
        Parameters:
        time - the timestamp to format
        unit - the time unit to use
        Returns:
        a date time string representation
      • format

        public String format​(Date time,
                             String format)
        Returns the formatted date in the specified format for a given date.
        Parameters:
        time - the date to format
        format - the date/time token
        Returns:
        a date time string representation
      • format

        public String format​(Date time,
                             TimeUnit unit)
        Returns the formatted date in the specified format for a given date, using the default format related to time unit.
        Parameters:
        time - the date to format
        unit - the time unit instance
        Returns:
        a date time string representation
      • add

        public Date add​(long time,
                        long amount,
                        TimeUnit unit)
        Adds the specified amount of unit to the given timestamp.
        Parameters:
        time - the input timestamp
        amount - the amount to add
        unit - the time unit instance
        Returns:
        new date with added units
      • add

        public Date add​(Date time,
                        long amount,
                        TimeUnit unit)
        Adds the specified amount of unit to the given date.
        Parameters:
        time - the input date
        amount - the amount to add
        unit - the time unit instance
        Returns:
        new date with added units
      • diff

        public double diff​(long maxTime,
                           long minTime,
                           TimeUnit unit)
        Returns the number of unit between the given timestamps.
        Parameters:
        maxTime - the input timestamp (reference)
        minTime - the timestamp to subtract
        unit - the time unit instance
        Returns:
        the number of unit between the given timestamps
      • diff

        public double diff​(Date maxTime,
                           Date minTime,
                           TimeUnit unit)
        Returns the number of unit between the given dates.
        Parameters:
        maxTime - the input date (reference)
        minTime - the date to subtract
        unit - the time unit instance
        Returns:
        the number of unit between the given dates
      • startOf

        public Date startOf​(long time,
                            TimeUnit unit)
        Returns the start of unit for the given timestamp.
        Parameters:
        time - the input timestamp
        unit - the time unit instance
        Returns:
        the start of unit for the given timestamp
      • startOf

        public Date startOf​(Date time,
                            TimeUnit unit)
        Returns the start of unit for the given date.
        Parameters:
        time - the input date
        unit - the time unit instance
        Returns:
        the start of unit for the given date
      • startOf

        public Date startOf​(long time,
                            IsoWeekDay weekday)
        Returns the start by weekday for the given timestamp.
        Parameters:
        time - the input timestamp
        weekday - the ISO day of the week (only needed if parameter "unit" is isoWeek).
        Returns:
        the start by weekday for the given date
      • startOf

        public Date startOf​(Date time,
                            IsoWeekDay weekday)
        Returns the start by weekday for the given date.
        Parameters:
        time - the input date
        weekday - the ISO day of the week (only needed if parameter "unit" is isoWeek).
        Returns:
        the start by weekday for the given date
      • endOf

        public Date endOf​(long time,
                          TimeUnit unit)
        Returns end of unit for the given timestamp.
        Parameters:
        time - the input timestamp
        unit - the time unit instance
        Returns:
        the end of unit for the given timestamp
      • endOf

        public Date endOf​(Date time,
                          TimeUnit unit)
        Returns end of unit for the given date.
        Parameters:
        time - the input date
        unit - the time unit instance
        Returns:
        the end of unit for the given date