/* Sets the correct weekday. 
If the time is never set then the device defaults to 1st January 1970 but with the wrong weekday set. This function ensures the weekday is correct in this case. */
static int set_day_of_week(const struct device *dev, time_t *unix_time)
/* Sets the correct weekday. 
If the time is never set then the device defaults to 1st January 1970 but with the wrong weekday set. This function ensures the weekday is correct in this case. */
static int set_day_of_week(const struct device *dev, time_t *unix_time)
{
	struct mcp7940n_data *data = dev->data;
	struct tm time_buffer = { 0 };
	int rc = 0;
	if (gmtime_r(unix_time, &time_buffer) != NULL) {
		data->registers.rtc_weekday.weekday = time_buffer.tm_wday;
		rc = write_register(dev, REG_RTC_WDAY,
			*((uint8_t *)(&data->registers.rtc_weekday)));
	} else {
		rc = -EINVAL;
	}
	return rc;
}