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

RTC "set seconds" sets late date #498

Closed
stc1988 opened this issue Nov 17, 2020 · 9 comments
Closed

RTC "set seconds" sets late date #498

stc1988 opened this issue Nov 17, 2020 · 9 comments

Comments

@stc1988
Copy link
Contributor

stc1988 commented Nov 17, 2020

Version: November 16, 2020
Build environment: Windows
Target device: M5stick_c

Description

Value of get seconds after set seconds is late date

Expected behavior
The value of set seconds and get seconds is same value

Images
IMG_2078

trace log before set rtc.seconds is Nov 17 2020, but displaying date of get rtc.seconds is Nov 19 2020

Steps to Reproduce

  1. build examples/drivers/m5stickc-rtc
    build command is mcconfig -d -m -p esp32/m5stick_c

  2. Press button B to set seconds to RTC.

@phoddie
Copy link
Collaborator

phoddie commented Nov 17, 2020

@wilberforce - I think this is your code. Would you take a look? (I don't have an M5 Stick C to try.) Thanks.

@wilberforce
Copy link
Contributor

wilberforce commented Nov 19, 2020 via email

@phoddie
Copy link
Collaborator

phoddie commented Nov 19, 2020

Cool, thanks.

@stc1988
Copy link
Contributor Author

stc1988 commented Nov 24, 2020

I added logs before _setDate and after _getDate in modules\drivers\rtc\rtc.js

set seconds(secs) {
	...
	trace(`[setDate]${date.month} ${date.date} ${date.year}\n`);
	this._setDate(date);
}
get seconds() {
	let date = this._getDate();
	trace(`[getDate]${date.month} ${date.date} ${date.year}\n`);

this is log when button B pressed

Set time: Tue Nov 24 2020 03:55:11 GMT-0900
1606222511.893
[setDate]10 26 2020
[getDate]10 26 2020

Values of setDate and getDate are the same vaue.
So bm8563.js works as exepeted, set seconds in rtc.js seems to have some issues

@wilberforce
Copy link
Contributor

wilberforce commented Nov 24, 2020

@stc1988
You discovered what I did and had not yet published.
There seems to be a day adjustment in rtc.js, I have simplified these to use javascript time functions, and it behaves as expected:


	get seconds() {
		let date = this._getDate();
		let when = new Date(date.year, date.month, date.date, date.hours, date.minutes, date.seconds, 0);
		return when.getTime() / 1000;
	}

	set seconds(secs) {
		let d = new Date(secs * 1000);
		let date = {
			date: d.getDate(),
			month: d.getMonth(),
			year: d.getFullYear(),
			dow: d.getDay(),
			hours: d.getHours(),
			minutes: d.getMinutes(),
			seconds: d.getSeconds()
		};
		this._setDate(date);
	}

@wilberforce
Copy link
Contributor

wilberforce commented Nov 24, 2020

Pull request here:

#501

@stc1988
Copy link
Contributor Author

stc1988 commented Nov 24, 2020

This year is leap year. Day adjustment problem is related to leap year.

Anyway, Using javascript time function is nice idea.
I will check some cases with your fix.

@stc1988
Copy link
Contributor Author

stc1988 commented Nov 25, 2020

@wilberforce
I confirmed some cases including leap day. It works as expected.
Thanks.

@stc1988
Copy link
Contributor Author

stc1988 commented Nov 28, 2020

I confirmed it works again with version November 27, 2020.

@stc1988 stc1988 closed this as completed Nov 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants