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

Date before Unix Epoch displays as 1 less day of month #30

Open
jorwoody opened this issue May 30, 2019 · 4 comments
Open

Date before Unix Epoch displays as 1 less day of month #30

jorwoody opened this issue May 30, 2019 · 4 comments
Labels

Comments

@jorwoody
Copy link

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')
}
@elena-p elena-p added the bug label May 31, 2019
@san3k1990
Copy link

I have the same problem. Sometimes the displayed date is 1 day less than the selected. is there any workaround?

@san3k1990
Copy link

the problem is observed for 1991-2010 years inclusive

@kriefsacha
Copy link

For me it's displaying right , but when i change it and save , it sends with one day less .. someone fixed it ?

@kriefsacha
Copy link

kriefsacha commented Mar 22, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants