Skip to content

Update SparkFun_RV8803.cpp #36

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

Closed
wants to merge 1 commit into from
Closed

Update SparkFun_RV8803.cpp #36

wants to merge 1 commit into from

Conversation

aetherius-ignis
Copy link

Set getEpoch to ignore timezone, always return epoch for gmt. This makes it possible that when we do a getEpoch we recover the same value added by setEpoch regardless of the configured time zone.

Set getEpoch to ignore timezone, always return epoch for gmt
@PaulZC
Copy link
Contributor

PaulZC commented Jan 23, 2025

Hi @aetherius-ignis ,

Please try running Example8 and post the results here.

Please also tell us what hardware you have tested your changes on. Have you tested multiple platforms and cores?

As you can see from the example, setEpoch and getEpoch need to be modified depending on what platform and core you are using.

Please also try changing setTimeZoneQuarterHours. Is the Epoch still as expected?

Best wishes,
Paul

@aetherius-ignis
Copy link
Author

Hi PaulZc

I thought it was a simple modification but it hid much more behind it, I was doing tests and the proposed solution is not valid because it only avoids daylight saving time, which corrects the time zone with which I provided the solution.

On the other hand, my hardware is a RV3032, its library is derived from this one, this generated a bit of confusion.

I was looking at the RV8803 library and I saw that my problem seems to be solved, unfortunately these changes are not available in the RV3032 library:
https://github.com/KineticLabs25/RV-3032-C7

After investigating the problem is the use of mktime itself, if it is replaced by timegm (although not available in time.h it was implemented in this library) the problem is solved.

I don't know how to request that the update of this library be propagated to the other one, for the moment I implemented a simple timegm function that seems to work, I have tested it with multiple timezones and the result seems consistent, I post it below in case it is of interest:

time_t RV3032::timegm(struct tm* tm) {
	// Convert to local time
	time_t t = mktime(tm);
	if (t == -1)
	{
		return -1;
	}
	// Get the corresponding UTC time
	struct tm* gmt = gmtime(&t);
	time_t utc_time = mktime(gmt);
	// Calculate the difference between local time and UTC
	double diff = difftime(utc_time, t);
	// Adjust local time to UTC
	return t - (time_t)diff;
}

PS: in addition to including this function it is necessary to change the mktime of the getEpoch function to timemg.

Sorry to have wasted your time.
Regards

@PaulZC
Copy link
Contributor

PaulZC commented Jan 24, 2025

Hi @aetherius-ignis ,

No problem! Thanks for the update.

Best wishes,
Paul

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

Successfully merging this pull request may close these issues.

2 participants