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.DateAdapter(ItemsEnvelop<NativeObject> envelop, DateAdapterOptions options)Creates a date adapter using the options passed as argument and the envelop whereScaleItemis stored.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Dateadd(long time, long amount, TimeUnit unit)Adds the specified amount of unit to the given timestamp.Dateadd(Date time, long amount, TimeUnit unit)Adds the specified amount of unit to the given date.doublediff(long maxTime, long minTime, TimeUnit unit)Returns the number of unit between the given timestamps.doublediff(Date maxTime, Date minTime, TimeUnit unit)Returns the number of unit between the given dates.DateendOf(long time, TimeUnit unit)Returns end of unit for the given timestamp.DateendOf(Date time, TimeUnit unit)Returns end of unit for the given date.Stringformat(long time, String format)Returns the formatted date in the specified format for a given timestamp.Stringformat(long time, TimeUnit unit)Returns the formatted date in the specified format for a given timestamp, using the default format related to time unit.Stringformat(Date time, String format)Returns the formatted date in the specified format for a given date.Stringformat(Date time, TimeUnit unit)Returns the formatted date in the specified format for a given date, using the default format related to time unit.DategetDateByOrdinal(int year, int ordinal)Returns aDateobject 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.DategetDateByWeek(int year, int week)Returns aDateobject and initializes it so that it represents midnight, at the beginning of the day specified by the week of the year, passed as arguments.doublegetEpochByOrdinal(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.doublegetEpochByWeek(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.DateAdapterFormatsgetFormats()Returns the provided default formats.DateAdapterOptionsgetOptions()Returns the options used to configure the date adapter.Dateparse(String time, String format)Parses the given value and return the associated date.DatestartOf(long time, IsoWeekDay weekday)Returns the start by weekday for the given timestamp.DatestartOf(long time, TimeUnit unit)Returns the start of unit for the given timestamp.DatestartOf(Date time, IsoWeekDay weekday)Returns the start by weekday for the given date.DatestartOf(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
-
DateAdapter
public DateAdapter(ItemsEnvelop<NativeObject> envelop, DateAdapterOptions options)
Creates a date adapter using the options passed as argument and the envelop whereScaleItemis stored.- Parameters:
envelop- envelop whereScaleItemis storedoptions- 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 aDateobject 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
Dateobject 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 aDateobject 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
Dateobject and initializes it so that it represents midnight
-
-