Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datetimepicker): invalid value passed to formatTime [MA-2131] #1881

Merged
merged 17 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 55 additions & 67 deletions docs/components/datetime-picker.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,47 @@

Create a single date selection calendar, with an example of passing in a fixed pixel width for the input field, and an empty string for `currentValue` which defaults the input to the placeholder message.

Set the `v-model` to [Single date time picker](#single-date-time-picker-v-model)
Set the `v-model` to [Single date time picker](#single-date-time-picker-v-model). Mode is set to `date`, which results in a calendar, but no timepicker.

<ClientOnly>
<KDateTimePicker
v-model="currentValue0"
v-model="singleDateEmpty"
clear-button
placeholder="Please select a date"
mode="date"
width="250"
:range="false"
/>
<br/>
<div>Emitted value: <pre class="json hide-from-percy">{{ JSON.stringify(currentValue0) }}</pre></div>
<div>Emitted value: <pre class="json hide-from-percy">{{ singleDateEmpty }}</pre></div>
</ClientOnly>

```html
<KDateTimePicker
v-model="currentValue"
@change="newVal => emitVal = newVal"
:range="false"
clear-button
placeholder="Please select a date"
mode="date"
width="250"
:range="false"
/>
```

### Single date and time

Set the `v-model` to [Single date time picker](#single-date-time-picker-v-model)
Setting the `v-model` to [Single date time picker](#single-date-time-picker-v-model) with a `start` value of `new Date()` will initialize the datepicker with today's date. Mode is set to `dateTime`, which results in a calendar, and a timepicker.

<ClientOnly>
<KDateTimePicker
v-model="currentValue1"
v-model="singleDateToday"
clear-button
placeholder="Please select a date and time"
mode="dateTime"
:minute-increment="5"
:range="false"
/>
<br/>
<div>Emitted value: <pre class="json hide-from-percy">{{ JSON.stringify(currentValue1) }}</pre></div>
<div>Emitted value: <pre class="json hide-from-percy">{{ singleDateToday }}</pre></div>
</ClientOnly>

```html
Expand All @@ -59,25 +58,24 @@ Set the `v-model` to [Single date time picker](#single-date-time-picker-v-model)
clear-button
placeholder="Please select a date and time"
mode="dateTime"
:minute-increment="5"
:range="false"
/>
```

### Date range

Set the `v-model` to [Range date time picker](#range-date-time-picker-v-model)
Set the `v-model` to [Range date time picker](#range-date-time-picker-v-model).

<ClientOnly>
<KDateTimePicker
v-model="currentValue2"
v-model="dateRangeWeek"
clear-button
placeholder="Please select a date range"
mode="date"
:range="true"
/>
<br/>
<div>Emitted value: <pre class="json hide-from-percy">{{ currentValue2 }}</pre></div>
<div>Emitted value: <pre class="json hide-from-percy">{{ dateRangeWeek }}</pre></div>
</ClientOnly>

```html
Expand All @@ -90,22 +88,20 @@ Set the `v-model` to [Range date time picker](#range-date-time-picker-v-model)
:range="true"
/>
```

### Date and time range

Set the `v-model` to [Range date time picker](#range-date-time-picker-v-model)

<ClientOnly>
<KDateTimePicker
v-model="currentValue3"
v-model="dateRangeWeek"
clear-button
placeholder="Please select a date and time"
mode="dateTime"
:minute-increment="5"
:range="true"
/>
<br/>
<div>Emitted value: <pre class="json hide-from-percy">{{ currentValue3 }}</pre></div>
<div>Emitted value: <pre class="json hide-from-percy">{{ dateRangeWeek }}</pre></div>
</ClientOnly>

```html
Expand All @@ -115,7 +111,6 @@ Set the `v-model` to [Range date time picker](#range-date-time-picker-v-model)
clear-button
placeholder="Please select a date and time"
mode="dateTime"
:minute-increment="5"
:range="true"
/>
```
Expand All @@ -124,23 +119,23 @@ Set the `v-model` to [Range date time picker](#range-date-time-picker-v-model)

Set the `v-model` to [Range date time picker](#range-date-time-picker-v-model)

Display both a calendar and relative time frames, passing in a preset week-long range. Hide the time.
This instance also makes use of the `minDate` and `maxDate` parameters, which are both optional.
Display both a calendar and relative time frames, passing in a preset week-long range. The `mode` is set to `relativeDate`, which only shows monthly calendar.

This instance makes use of the optional `minDate` and `maxDate` parameters.

<ClientOnly>
<KDateTimePicker
v-model="currentValue4"
v-model="dateRangeWeek"
placeholder="Please select a range"
mode="relativeDate"
width="415"
:min-date="minDate"
:max-date="maxDate"
:minute-increment="5"
:range="true"
:time-periods="exampleTimeFrames"
/>
<br/>
<div>Emitted value: <pre class="json hide-from-percy">{{ currentValue4 }}</pre></div>
<div>Emitted value: <pre class="json hide-from-percy">{{ dateRangeWeek }}</pre></div>
</ClientOnly>

```html
Expand All @@ -152,7 +147,6 @@ This instance also makes use of the `minDate` and `maxDate` parameters, which ar
width="415"
:min-date="minDate"
:max-date="maxDate"
:minute-increment="5"
:range="true"
:time-periods="[
{
Expand Down Expand Up @@ -186,23 +180,23 @@ This instance also makes use of the `minDate` and `maxDate` parameters, which ar

Set the `v-model` to [Range date time picker](#range-date-time-picker-v-model)

Display both a calendar and relative time frames, passing in a preset week-long range.
This instance also makes use of the `minDate` and `maxDate` parameters, which are both optional.
Display both a calendar and relative time frames, passing in a preset week-long range. This instance makes use of the optional `minDate` and `maxDate` parameters.

Passing in a `timePeriodsKey` causes the instance to default to the "Relative" tab.

<ClientOnly>
<KDateTimePicker
v-model="currentValue5"
v-model="dateRangeWeekRelative"
placeholder="Please select a range"
mode="relativeDateTime"
width="415"
:min-date="minDate"
:max-date="maxDate"
:minute-increment="5"
:range="true"
:time-periods="exampleTimeFrames"
/>
<br/>
<div>Emitted value: <pre class="json hide-from-percy">{{ currentValue5 }}</pre></div>
<div>Emitted value: <pre class="json hide-from-percy">{{ dateRangeWeekRelative }}</pre></div>
</ClientOnly>

```html
Expand All @@ -214,7 +208,6 @@ This instance also makes use of the `minDate` and `maxDate` parameters, which ar
width="415"
:min-date="minDate"
:max-date="maxDate"
:minute-increment="5"
:range="true"
:time-periods="[
{
Expand Down Expand Up @@ -244,24 +237,24 @@ This instance also makes use of the `minDate` and `maxDate` parameters, which ar
/>
```

### Relative date and time
### Relative date and time only

Set the `v-model` to [Range date time picker](#range-date-time-picker-v-model)
This utilizes the same time frames as the previous example; however, in this example we are passing in a pre-selected time frame.
Set the `v-model` to [Range date time picker](#range-date-time-picker-v-model).
This utilizes the same time frames as the previous example; however, in this case we are passing in a pre-selected time frame of one hour, and.

<ClientOnly>
<KDateTimePicker
v-model="currentValue6"
v-model="oneHourRelativeOnly"
placeholder="Please select a time frame"
mode="relative"
mode="relativeDate"
width="480"
:min-date="minDate"
:max-date="maxDate"
:range="true"
:time-periods="exampleTimeFrames"
/>
<br/>
<div>Emitted value: <pre class="json hide-from-percy">{{ currentValue6 }}</pre></div>
<div>Emitted value: <pre class="json hide-from-percy">{{ oneHourRelativeOnly }}</pre></div>
</ClientOnly>

```html
Expand Down Expand Up @@ -308,13 +301,13 @@ This utilizes the same time frames as the previous example; however, in this exa

#### Single date time picker `v-model`

A single date or time picker instance which can be seeded with a value as shown here, where `currentValue` is a valid Date object, eg: `new Date()` or an empty string, eg: `''` which will display the placeholder message.
A single date or time picker instance which can be seeded with a value as shown here, where `currentValue`'s `start` key contains a valid Date object, `new Date()` or an empty string, `''`. If empty, the picker will display the placeholder message and allow the user to make a selection.

```ts
<KDateTimePicker
v-model="currentValue"
...
/>
currentValue = {
start: new Date(),
end: null,
},
```

#### Range date time picker `v-model`
Expand All @@ -325,8 +318,8 @@ Can be seeded with a **relative time frame** by setting the `v-model` to `curren

```ts
currentValue = {
start: '',
end: '',
start: null,
end: null,
timePeriodsKey: TimeframeKeys.ONE_DAY
},
```
Expand Down Expand Up @@ -391,7 +384,7 @@ Required `String` prop which accepts the following values:

### range

`Boolean` which determines whether the calendar allows selection of a **single** date or time, as opposed to a **range** of start and end values.
`Boolean` which determines whether the calendar allows selection of a **single** date or time, as opposed to a **range** of start and end values. Choosing any relative `mode` option will default the `range` to `true`.

**default**: `false`

Expand Down Expand Up @@ -440,10 +433,14 @@ The events below will fire whenever **Apply** is clicked (assuming the user has

**Events**: `change`, `update:modelValue`

Will emit a JavaScript Date object, or an empty string "Clear".
Component will emit a JavaScript Date object for the `start` value, and a null value for `end`.
When "Clear" is clicked, it will emit null values for both `start` and `end`.

```ts
"2022-09-06T19:45:54.406Z" // ISO 8601 Date string
{
start: "2022-09-06T19:45:54.406Z",
end: null,
},
```

### Range date time picker
Expand All @@ -457,7 +454,7 @@ Will emit an `object` containing the following values:
"start": "2022-09-06T19:45:54.406Z", // ISO 8601 Date string
"end": "2022-09-07T19:45:54.406Z", // ISO 8601 Date string
"timePeriodsKey": "24h" // or "" if not applicable
}
}
```

<script>
Expand Down Expand Up @@ -501,36 +498,27 @@ export default {
const aWeekAgo = new Date(today.getTime() - (7*24*60*60*1000))
const aYearAgo = new Date(today.getTime() - (365*24*60*60*1000))
return {
currentValue0: new Date(),
currentValue1: new Date(),
currentValue2: {
start: twoDaysAgo,
end: today
},
currentValue3: {
start: twoDaysAgo,
end: today
singleDateEmpty: {
start: null,
end: null
},
currentValue4: {
start: twoDaysAgo,
end: today
singleDateToday: {
start: today,
end: null
},
currentValue5: {
dateRangeWeek: {
start: aWeekAgo,
end: today
},
currentValue6: {
dateRangeWeekRelative: {
start: aWeekAgo,
end: today,
timePeriodsKey: TimeframeKeys.SEVEN_DAY
},
rangeTwoday: {
start: twoDaysAgo,
end: today
},
rangeWeek: {
start: aWeekAgo,
end: today
oneHourRelativeOnly: {
start: null,
end: null,
timePeriodsKey: TimeframeKeys.ONE_HOUR
},
maxDate: today,
minDate: aYearAgo,
Expand Down
15 changes: 15 additions & 0 deletions docs/guide/migrating-to-version-9.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ Kongponents styles are no longer designed to be utilized standalone, separately

### KDateTimePicker

#### Props

* `v-model` Single date and time picker's seed value (string in ISO date format) has been deprecated in favor of a `TimeRange` object whose `start` value will be set to a Date ISO string; `end` value will be set to `null`.
mihai-peteu marked this conversation as resolved.
Show resolved Hide resolved

See KDateTimePickers's [v-model](/components/datetime-picker#v-model) for more details

#### Events

* `change`, `update:modelValue` – a Single date and time picker will no longer emit an ISO date format string. Instead, a `TimeRange` object with a Date ISO string `start` value, and a null `end` value will be emitted.

See KDateTimePickers's [Single date time picker events](/components/datetime-picker#single-date-time-picker) for more details

#### Constants, Types & Interfaces

* `TimeRange` - `start` and `end` keys are now defined as `Date | null`
mihai-peteu marked this conversation as resolved.
Show resolved Hide resolved

### KDropdownMenu

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"sortablejs": "^1.15.0",
"swrv": "^1.0.4",
"uuid": "^9.0.1",
"v-calendar": "^3.0.3",
"v-calendar": "^3.1.2",
"vue-draggable-next": "^2.2.1"
},
"peerDependencies": {
Expand Down
Loading