Skip to content

Commit 6fb1dd6

Browse files
authored
fix(ui5-daypicker): show correct today (#1157)
1 parent 7219b43 commit 6fb1dd6

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

packages/base/src/dates/CalendarDate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class CalendarDate {
149149
function isValidDate(date) {
150150
return date && Object.prototype.toString.call(date) === "[object Date]" && !isNaN(date); // eslint-disable-line
151151
}
152-
if (!isValidDate()) {
152+
if (!isValidDate(oJSDate)) {
153153
throw new Error(`Date parameter must be a JavaScript Date object: [${oJSDate}].`);
154154
}
155155
return new CalendarDate(oJSDate.getFullYear(), oJSDate.getMonth(), oJSDate.getDate(), sCalendarType);

packages/main/src/DayPicker.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,7 @@ class DayPicker extends UI5Element {
174174
lastWeekNumber = weekNumber;
175175
}
176176

177-
const isToday = (oCalDate.getDate() === this._currentCalendarDate.getDate())
178-
&& (oCalDate.getMonth() === this._currentCalendarDate.getMonth())
179-
&& (oCalDate.getYear() === this._currentCalendarDate.getYear());
177+
const isToday = oCalDate.isSame(CalendarDate.fromLocalJSDate(new Date(), this._primaryCalendarType));
180178

181179
week.push(day);
182180

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<script>delete Document.prototype.adoptedStyleSheets;</script>
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta charset="utf-8">
8+
<title>i18n Demo</title>
9+
10+
<script src="../../webcomponentsjs/webcomponents-loader.js"></script>
11+
<script src="../../resources/bundle.esm.js" type="module"></script>
12+
<script nomodule src="../../resources/bundle.es5.js"></script>
13+
14+
<script>delete Document.prototype.adoptedStyleSheets;</script>
15+
16+
</head>
17+
18+
19+
<body>
20+
21+
<style>
22+
.snippet {
23+
display: flex;
24+
width: 50%;
25+
flex-direction: column;
26+
margin: auto;
27+
margin-top: 200px;
28+
}
29+
</style>
30+
31+
<div class="snippet">
32+
33+
<ui5-datepicker></ui5-datepicker>
34+
35+
<br>
36+
<br>
37+
38+
<!-- <ui5-daypicker></ui5-daypicker> -->
39+
40+
41+
<br>
42+
<br>
43+
44+
<ui5-textarea maxlength="20" show-exceeded-text></ui5-textarea>
45+
46+
<br>
47+
<br>
48+
49+
<span>Martin's cheat sheet</span>
50+
51+
<hr>
52+
mañana, ayer
53+
</div>
54+
</body>
55+
56+
</html>

0 commit comments

Comments
 (0)