Skip to content

Commit a706686

Browse files
committed
datepicker: firstDayOfWeek and parseDateFromString
1 parent c0e6dd8 commit a706686

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

docs/documentation/docs/controls/DateTimePicker.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ The `DateTimePicker` control can be configured with the following properties:
5353
| label | string | no | Property field label displayed on top. |
5454
| disabled | boolean | no | Specifies if the control is disabled or not. |
5555
| formatDate | function | no | Defines a formatDate function that can override the output value in Date picker. |
56+
| parseDateFromString | function | no | Optional method to parse the text input value to date, it is only useful when allowTextInput is set to true |
5657
| dateConvention | DateConvention | no | Defines the date convention to use. The default is date and time.|
5758
| timeConvention | TimeConvention | no | Defines the time convention to use. The default value is the 24-hour clock convention. |
5859
| firstDayOfWeek | DayOfWeek | no | Specify the first day of the week for your locale. |
60+
| firstWeekOfYear | FirstWeekOfYear | no | Defines when the first week of the year should start. |
5961
| key | string | no | A unique key that indicates the identity of this control |
6062
| onGetErrorMessage | function | no | The method is used to get the validation error message and determine whether the input value is valid or not. See [this documentation](https://learn.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/guidance/validate-web-part-property-values) to learn how to use it. |
6163
| showGoToToday | boolean | no | Controls whether the "Go to today" link should be shown or not |

src/controls/dateTimePicker/DateTimePicker.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,15 @@ export class DateTimePicker extends React.Component<IDateTimePickerProps, IDateT
227227
timeConvention,
228228
dateConvention = DateConvention.DateTime,
229229
firstDayOfWeek,
230+
firstWeekOfYear,
230231
isMonthPickerVisible = true,
231232
showGoToToday,
232233
allowTextInput = true,
233234
showMonthPickerAsOverlay = false,
234235
showWeekNumbers = false,
235236
showSeconds = false,
236237
formatDate,
238+
parseDateFromString,
237239
value = this.state.day,
238240
strings: dateStrings = new DateTimePickerStrings(), // Defines the DatePicker control labels
239241
timeDisplayControlType,
@@ -322,13 +324,15 @@ export class DateTimePicker extends React.Component<IDateTimePickerProps, IDateT
322324
<div className={styles.picker}>
323325
<DatePicker
324326
formatDate={formatDate}
327+
parseDateFromString={parseDateFromString}
325328
disabled={disabled}
326329
value={value}
327330
strings={dateStrings}
328331
isMonthPickerVisible={isMonthPickerVisible}
329332
onSelectDate={this.onSelectDate}
330333
allowTextInput={allowTextInput}
331334
firstDayOfWeek={firstDayOfWeek}
335+
firstWeekOfYear={firstWeekOfYear}
332336
showGoToToday={showGoToToday}
333337
showMonthPickerAsOverlay={showMonthPickerAsOverlay}
334338
showWeekNumbers={showWeekNumbers}

src/controls/dateTimePicker/IDateTimePickerProps.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { FirstWeekOfYear } from '@fluentui/react-northstar';
12
import { DayOfWeek } from 'office-ui-fabric-react/lib/utilities/dateValues/DateValues';
23
import { TimeConvention, DateConvention } from './DateTimeConventions';
34
import { IDateTimePickerStrings } from './IDateTimePickerStrings';
@@ -24,6 +25,10 @@ export interface IDateTimePickerProps {
2425
* By defaut date.toDateString() is used.
2526
*/
2627
formatDate?: (date: Date) => string;
28+
/**
29+
* Optional method to parse the text input value to date, it is only useful when allowTextInput is set to true
30+
*/
31+
parseDateFromString?: (dateStr: string) => Date;
2732
/**
2833
* Defines the date convention to use. The default is date and time.
2934
*/
@@ -36,6 +41,10 @@ export interface IDateTimePickerProps {
3641
* Specify the first day of the week for your locale.
3742
*/
3843
firstDayOfWeek?: DayOfWeek;
44+
/**
45+
* Defines when the first week of the year should start, FirstWeekOfYear.FirstDay, FirstWeekOfYear.FirstFullWeek or FirstWeekOfYear.FirstFourDayWeek are the possible values
46+
*/
47+
firstWeekOfYear?: FirstWeekOfYear
3948
/**
4049
* An UNIQUE key indicates the identity of this control
4150
*/

0 commit comments

Comments
 (0)