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.DateAdapterFormats
getFormats()
Returns the provided default formats.String
getId()
Returns the date adapter id.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
-
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 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
-
-