Class DateAdapter
- java.lang.Object
-
- org.pepstock.charba.client.adapters.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 Summary
Constructors Constructor Description DateAdapter()
Creates a date adapter without any options.DateAdapter(DateAdapterOptions options)
Creates a date adapter using the options passed as argument.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Date
add(long time, long amount, TimeUnit unit)
Adds the specified amount of unit to the given timestamp.Date
add(Date time, long amount, TimeUnit unit)
Adds the specified amount of unit to the given date.double
diff(long maxTime, long minTime, TimeUnit unit)
Returns the number of unit between the given timestamps.double
diff(Date maxTime, Date minTime, TimeUnit unit)
Returns the number of unit between the given dates.Date
endOf(long time, TimeUnit unit)
Returns end of unit for the given timestamp.Date
endOf(Date time, TimeUnit unit)
Returns end of unit for the given date.String
format(long time, String format)
Returns the formatted date in the specified format for a given timestamp.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.String
format(Date time, String format)
Returns the formatted date in the specified format for a given date.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.Date
getDateByOrdinal(int year, int ordinal)
Returns aDate
object and initializes it so that it represents midnight, at the beginning of the day specified by the ordinal day of a year, passed as arguments.Date
getDateByWeek(int year, int week)
Returns aDate
object and initializes it so that it represents midnight, at the beginning of the day specified by the week of the year, passed as arguments.double
getEpochByOrdinal(int year, int ordinal)
Returns the number of milliseconds, since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT, for a specific ordinal day of a year.double
getEpochByWeek(int year, int week)
Returns the number of milliseconds, since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT, for a specific week of a year.DateAdapterFormats
getFormats()
Returns the provided default formats.DateAdapterOptions
getOptions()
Returns the options used to configure the date adapter.Date
parse(String time, String format)
Parses the given value and return the associated date.Date
startOf(long time, IsoWeekDay weekday)
Returns the start by weekday for the given timestamp.Date
startOf(long time, TimeUnit unit)
Returns the start of unit for the given timestamp.Date
startOf(Date time, IsoWeekDay weekday)
Returns the start by weekday for the given date.Date
startOf(Date time, TimeUnit unit)
Returns the start of unit for the given date.
-
-
-
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
-
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 formatformat
- 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 formatunit
- 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 formatformat
- 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 formatunit
- 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 timestampamount
- the amount to addunit
- 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 dateamount
- the amount to addunit
- 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 subtractunit
- 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 subtractunit
- 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 timestampunit
- 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 dateunit
- 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 timestampweekday
- 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 dateweekday
- 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 timestampunit
- 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 dateunit
- the time unit instance- Returns:
- the end of unit for the given date
-
getEpochByWeek
public double getEpochByWeek(int year, int week)
Returns the number of milliseconds, since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT, for a specific week of a year.- Parameters:
year
- the yearweek
- the week of year- Returns:
- the number of milliseconds, since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT
-
getDateByWeek
public Date getDateByWeek(int year, int week)
Returns aDate
object and initializes it so that it represents midnight, at the beginning of the day specified by the week of the year, passed as arguments.- Parameters:
year
- the yearweek
- the week of year- Returns:
- a
Date
object and initializes it so that it represents midnight
-
getEpochByOrdinal
public double getEpochByOrdinal(int year, int ordinal)
Returns the number of milliseconds, since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT, for a specific ordinal day of a year.- Parameters:
year
- the yearordinal
- the ordinal day of year- Returns:
- the number of milliseconds, since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT
-
getDateByOrdinal
public Date getDateByOrdinal(int year, int ordinal)
Returns aDate
object and initializes it so that it represents midnight, at the beginning of the day specified by the ordinal day of a year, passed as arguments.- Parameters:
year
- the yearordinal
- the ordinal day of year- Returns:
- a
Date
object and initializes it so that it represents midnight
-
-