Describe the bug
Calling getValue from SohoDatePickerComponent returns the selected date as string. The method is defined as public getValue(): Date and should return a value with type Date.
To Reproduce
Steps to reproduce the behavior:
console.log('DatePickerDemoComponent.onChange(date of datepicker): ' + this.datepicker?.getValue());.npm start.DatePickerDemoComponent.onChange(date of datepicker): 12/13/2016.Expected behavior
In general I expect a Date object after calling getValue instead of string. The steps "To Reproduce" should end with the following log message: DatePickerDemoComponent.onChange(date of datepicker): [object Object]. And the type of object should be Date to call according methods on it.
Version
Screenshots
no screenshots
Platform
Additional context
no additional context
The only thing we could change is the type. It should actually be saying its a string here https://github.com/infor-design/enterprise-ng/blob/master/projects/ids-enterprise-ng/src/lib/datepicker/soho-datepicker.component.ts#L389
The component underneath returns a string here because you may want the formatted value and thats whats shown in the field.
You can use the Locale functions to convert it to a date. For example
Soho.Locale.parseDate('2020-02-26 涓嬪崍12:00', { pattern: 'yyyy/M/d ah:mm' })
// or with no params for the current locales format
Soho.Locale.parseDate(component.getValue());
Okay I understand. Changing the type of getValue would be very helpful for the right expectation of the returned value. Maybe it's possible to add another method which returns the value from https://github.com/infor-design/enterprise/blob/c5d013bd6c7386ff63046fc51478dd2c076cdbf4/src/components/datepicker/datepicker.js#L1954? So everybody is able to use the standard without doing own parsing stuff.
Ok, yeah i think maybe a getDateValue() could be an idea. So
To avoid a breaking change the option to value seems better for me. The current method can be changed into
public getValue(asDate: boolean = false): string | Date {
if (asDate) {
return this.jQueryElement.getCurrentDate();
}
return this.internalValue;
}
or something like that. So we have the same behavior if we call getValue() like today and the additional Date value with getValue(true).
OK, As this is open source you could try a pull request. This seems good to me. You could also even do it all in the NG project as in...
public getValue(asDate: boolean = false): string | Date {
if (asDate) {
return Soho.Locale.parseDate(this.internalValue);
}
return this.internalValue;
}
Since we are reworking the datepicker API and i'd rather do this sort of change to enterprise then.
I will try a pull request with pleasure @tmcconechy! Your notice about reworking the datepicker API is new to me so I try to solve the parsing in NG project. My idea before was to use existing functionality in enterprise but I skip this.
yeah please do! the new stuff will be a while. so if you want a fix soon that would be the best way