nativescript-datetimepicker
nativescript-datetimepicker copied to clipboard
Date before Unix Epoch displays as 1 less day of month
Which platform(s) does your issue occur on?
- Android
Please, provide the following version numbers that your issue occurs with:
- CLI: 5.3.1
- Cross-platform modules: 5.3.2
- Runtime(s): 5.3.1
- Plugins: "dayjs": "^1.8.14",
Please, tell us how to recreate the issue in as much detail as possible.
- Create a DatePickerField and use ngModel to bind a Date object.
- Provide a dateFormat of "yyyy-MM-dd"
- enter a date before Unix Epoch (such as July 11, 1961) ISSUE:
- dates of certain years will display as 1 day prior to selected date ex. July 11, 1961 displays as July 10, 1961 ex. July 11, 1962 displays as July 10, 1962 ex. July 11, 1965 displays as July 10, 1965
Testing several years before 1970, it appears to happen for '61, '62, '64, '65.
NOTE:
- entering most other years seems to work as expected... ex. July 11, 1963 displays as July 11, 1963
- tested many years before 1960 and some years after 1970 with expected results
NOTE 2:
- it seems to only affect the display value... when opening the datepicker again, the selected value is what was originally selected (ex. select July 11, 1961; shows as July 10, 1961; opening datepicker again shows July 11, 1961)
Is there any code involved?
Template:
...
<DatePickerField
[ngModel]="dateOfBirth"
(ngModelChange)="onDateOfBirthChanged($event)"
[hint]="'YYYY-MM-DD' | localize"
dateFormat="yyyy-MM-dd"
></DatePickerField>
...
Code behind:
dateOfBirth: Date = undefined
dateOfBirthString: string
...
onDateOfBirthChanged(dob: string) {
if (!dob) {
return
}
const dateObj = dayjs(dob)
if (!dateObj.isValid()) {
return
}
this.dateOfBirth = dateObj.toDate()
this.dateOfBirthString = dateObj.format('YYYY-MM-DD')
}
I have the same problem. Sometimes the displayed date is 1 day less than the selected. is there any workaround?
the problem is observed for 1991-2010 years inclusive
For me it's displaying right , but when i change it and save , it sends with one day less .. someone fixed it ?
Okay guys i just fixed it with :
this.birthDate.setMinutes(this.birthDate.getMinutes() - this.birthDate.getTimezoneOffset());
I remembered that i used it somewhere so i tried and it worked.