4
4
[ ![ Maven Central] ( https://img.shields.io/maven-central/v/com.flowingcode.vaadin.addons/template-addon )] ( https://mvnrepository.com/artifact/com.flowingcode.vaadin.addons/template-addon )
5
5
[ ![ Javadoc] ( https://img.shields.io/badge/javadoc-00b4f0 )] ( https://javadoc.flowingcode.com/artifact/com.flowingcode.vaadin.addons/template-addon )
6
6
7
- # Template Add-on
7
+ # DateTimeRangePicker Add-on for Vaadin
8
8
9
- This is a template project for building new Vaadin 24 add-ons
9
+ DateTimeRangePicker is a component add-on for Vaadin Framework version 14+ that assists
10
+ on the creation of
11
+ [ time intervals] ( https://en.wikipedia.org/wiki/ISO_8601#Time_intervals )
12
+ (a time period delimited by two instants),
13
+ that conform to certain date and time constraints.
14
+ It includes a DateTimeRange class with an API to operate TimeInterval class instances.
10
15
11
- ## Features
16
+ As an example, you could set the component to handle time intervals that occur every weekend from 8:30 to 12:30 AM between the
17
+ 1st and 15th of May 2025. Then, you would get a DateTimeRange object and use it to consult if a certain instant is included
18
+ or when will the next time interval start.
19
+
20
+ ** Note:** current implementation ** does not** support custom time zones. It uses the system's default.
12
21
13
- * List the features of your add-on in here
22
+ ## Features
23
+ - Customizable selection of date, time and days.
24
+ - API to create and query time intervals. It supports two work modes:
25
+ - ** Lazy** mode (default): does not store time intervals and instead creates them when requested.
26
+ - ** Eager** mode: valid time intervals must be created and stored before any request is made.
14
27
15
28
## Online demo
16
29
@@ -27,7 +40,7 @@ Add the following dependencies in your pom.xml file:
27
40
``` xml
28
41
<dependency >
29
42
<groupId >com.flowingcode.vaadin.addons</groupId >
30
- <artifactId >template -addon</artifactId >
43
+ <artifactId >date-time-range-picker -addon</artifactId >
31
44
<version >X.Y.Z</version >
32
45
</dependency >
33
46
```
@@ -69,13 +82,52 @@ Then, follow these steps for creating a contribution:
69
82
70
83
This add-on is distributed under Apache License 2.0. For license terms, see LICENSE.txt.
71
84
72
- TEMPLATE_ADDON is written by Flowing Code S.A.
85
+ DateTimeRangePicker is written by Flowing Code S.A.
73
86
74
87
# Developer Guide
75
88
76
89
## Getting started
77
90
78
- Add your code samples in this section
91
+ A simple instantiation.
92
+ ```
93
+ DateTimeRangePicker addon = new DateTimeRangePicker();
94
+ addon.setMinDate(LocalDate.now());
95
+ addon.setMaxDate(LocalDate.now().plusDays(15));
96
+ addon.setWeekDays(DayOfWeek.MONDAY, DayOfWeek.FRIDAY);
97
+ ```
98
+ Component will have monday and friday set by default and user will not
99
+ be allowed to select a start date earlier than today and an end date later than today plus fifteen days.
100
+
101
+ ## Binding
102
+
103
+ Here ** Pojo** has a ** DateTimeRange** variable with getter and setter methods.
104
+
105
+ ```
106
+ DateTimeRangePicker addon = new DateTimeRangePicker();
107
+ Binder<Pojo> binder = new Binder<>(Pojo.class);
108
+ binder.forField(addon).bind(Pojo::getDateTimeRange, Pojo::setDateTimeRange);
109
+ binder.setBean(pojo);
110
+ ```
111
+ After a successful validation you can use the return value to make queries.
112
+
113
+ ```
114
+ TimeInterval interval = pojo.getDateTimeRange().getNextInterval();
115
+ boolean includes = interval != null && interval.includes(LocalDateTime.now());
116
+ ```
117
+
118
+ ## DateTimeRange modes
119
+ As described above, by default ** TimeInterval**
120
+ instances are not stored but created and returned when needed. This is called ** Lazy** mode.
121
+
122
+ When the dataset is small, switching to ** Eager** mode may yield better results, as the objects are created all at once.
123
+ If you do, remember to call refresh() whenever the state of the DateTimeRange object changes.
124
+
125
+
126
+ ```
127
+ dateTimeRange.setFetchMode(FetchMode.EAGER);
128
+ dateTimeRange.refresh();
129
+ ```
130
+
79
131
80
132
## Special configuration when using Spring
81
133
0 commit comments