Skip to content

Commit a7f9cf5

Browse files
Felipe Langjavier-godoy
authored andcommitted
feat: add option to use double digit hours
Close #32
1 parent 5e7b8a0 commit a7f9cf5

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/main/java/com/flowingcode/vaadin/addons/simpletimer/SimpleTimer.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ public void setHours(final boolean hours) {
109109
getElement().setProperty("hours", hours);
110110
}
111111

112+
/**
113+
* Use two digits for hours.
114+
*
115+
* @param doubleDigitHours true to format hours using two digits.
116+
*/
117+
public void setDoubleDigitHours(final boolean doubleDigitHours) {
118+
getElement().setProperty("doubleDigitHours", doubleDigitHours);
119+
}
120+
112121
/** Starts or stops the timer if it is already started */
113122
public void start() {
114123
getElement().callJsFunction("start");

src/main/resources/META-INF/frontend/simple-timer/simple-timer.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ Polymer({
9696
type: Boolean,
9797
value: false
9898
},
99+
/**
100+
* Use two digits for hours
101+
* @default false
102+
*/
103+
doubleDigitHours: {
104+
type: Boolean,
105+
value: false
106+
},
99107
/**
100108
* Time the timer has spent running since it was started
101109
*/
@@ -177,6 +185,9 @@ Polymer({
177185
seconds = this.minutes || this.hours ? seconds % 60 : seconds;
178186
seconds = seconds < 10 ? '0' + seconds : seconds;
179187

188+
if(this.hours && this.doubleDigitHours) {
189+
hours = hours.toString().padStart(2, '0');
190+
}
180191
return (this.hours ? hours + ':' : '') + (this.minutes || this.hours ? minutes + ':' : '') + seconds + (this.fractions ? ('.' + timeString[1].substring(0,2)) : '')
181192
}
182193
});

src/test/java/com/flowingcode/vaadin/addons/simpletimer/SimpletimerDemo.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public SimpletimerDemo() {
8585
fractions.addValueChangeListener(e -> timer.setFractions(e.getValue()));
8686
final Checkbox minutes = new Checkbox("Minutes", e -> timer.setMinutes(e.getValue()));
8787
final Checkbox hours = new Checkbox("Hours", e -> timer.setHours(e.getValue()));
88+
final Checkbox doubleDigitHours =
89+
new Checkbox("Double digit hours", e -> timer.setDoubleDigitHours(e.getValue()));
8890
final Checkbox visible =
8991
new Checkbox(
9092
"Visible",
@@ -98,8 +100,10 @@ public SimpletimerDemo() {
98100
final HorizontalLayout topLayout = new HorizontalLayout(timerTitle, timer);
99101
topLayout.setAlignItems(Alignment.CENTER);
100102

101-
HorizontalLayout options = new HorizontalLayout(countUp, fractions, minutes, hours, visible);
103+
HorizontalLayout options =
104+
new HorizontalLayout(countUp, fractions, minutes, hours, visible, doubleDigitHours);
102105
options.setAlignItems(Alignment.CENTER);
106+
options.getStyle().set("flex-wrap", "wrap");
103107

104108
final HorizontalLayout bottomLayout = new HorizontalLayout(start, stop, reset, running);
105109
bottomLayout.setAlignItems(Alignment.BASELINE);

0 commit comments

Comments
 (0)