refactor time setting to make a little more sense

now you set time in local time. If time zone hasn't been set already,
it'll prompt you to enter a time zone.

The main oddity is now that you have to know your time zone as
an offset from UTC. This can be fixed later with a proper symbolic
TZ to numeric mapping, but, that's actually a surprisingly hard
feature to implement.
This commit is contained in:
bunnie 2022-03-28 03:37:27 +08:00
parent 91ed8193a7
commit c78273f540
4 changed files with 151 additions and 122 deletions

View file

@ -1,110 +0,0 @@
{
"rtc.month": {
"en": "Enter month (1-12)",
"ja": "月(1-12)を入力してください。",
"zh": "输入月份 (1-12)",
"en-tts": "Enter month one through twelve"
},
"rtc.day": {
"en": "Enter day (1-31)",
"ja": "日数 (1-31) を入力してください。",
"zh": "输入日期 (1-31)",
"en-tts": "Enter day one through 31"
},
"rtc.year": {
"en": "Enter last two digits of year",
"ja": "西暦の下2桁を入力してください。",
"zh": "输入年份 (最后两位数)",
"en-tts": "Enter last two digits of year"
},
"rtc.bodge": {
"en": "Enter the system time in ⚠UTC⚠.\nThis is likely not the same thing as your local time.",
"ja": "システム時刻を⚠UTC⚠に入力します。\nこれは現地時間と同じではない可能性があります。",
"zh": "以⚠UTC⚠输入系统时间。\n这可能与您的本地时间不同。",
"en-tts": "Enter the system time in ⚠UTC⚠.\nThis is likely not the same thing as your local time."
},
"rtc.hour": {
"en": "Enter hours for UTC (0-23)",
"ja": "UTC時間(0-23)を入力してください。",
"zh": "输入UTC小时 (0-23)",
"en-tts": "Enter hours for UTC as 24 hour format"
},
"rtc.minute": {
"en": "Enter minutes (0-59)",
"ja": "分(0-59)を入力してください。",
"zh": "输入分钟 (0-59)",
"en-tts": "Enter minutes"
},
"rtc.seconds": {
"en": "Enter seconds (0-59)",
"ja": "秒 (0-59) を入力してください。",
"zh": "输入秒数 (0-59)",
"en-tts": "Enter seconds"
},
"rtc.day_of_week": {
"en": "Select the day of week",
"ja": "曜日を選択してください。",
"zh": "[星期几]清单框",
"en-tts": "Select the day of week"
},
"rtc.monday": {
"en": "Monday",
"ja": "月曜日",
"zh": "星期一",
"en-tts": "Monday"
},
"rtc.tuesday": {
"en": "Tuesday",
"ja": "火曜日",
"zh": "星期二",
"en-tts": "Tuesday"
},
"rtc.wednesday": {
"en": "Wednesday",
"ja": "水曜日",
"zh": "星期三",
"en-tts": "Wednesday"
},
"rtc.thursday": {
"en": "Thursday",
"ja": "木曜日",
"zh": "星期四",
"en-tts": "Thursday"
},
"rtc.friday": {
"en": "Friday",
"ja": "金曜日",
"zh": "星期五",
"en-tts": "Friday"
},
"rtc.saturday": {
"en": "Saturday",
"ja": "土曜日",
"zh": "星期六",
"en-tts": "Saturday"
},
"rtc.sunday": {
"en": "Sunday",
"ja": "日曜日",
"zh": "星期日",
"en-tts": "Sunday"
},
"rtc.timezone": {
"en": "Please enter your local offset from UTC in hours (-12.0 to +14.0 hours).\nNote: this offset does not yet track daylight savings.",
"ja": "UTCからのローカルオフセットを時間単位で入力してください(-12.0〜 + 14.0時間):",
"zh": "请以小时为单位输入您与 UTC 的本地偏移量(-12.0 到 +14.0 小时):",
"en-tts": "Please enter your local offset from UTC in hours (-12.0 to +14.0 hours):"
},
"rtc.integer_err": {
"en": "Error: entry was not numeric",
"ja": "エラー:エントリは数値ではありませんでした。",
"zh": "错误:输入不是数字",
"en-tts": "Error: entry was not numeric"
},
"rtc.range_err": {
"en": "Error: input out of range",
"ja": "エラー:入力が範囲外です。",
"zh": "错误:输入超出范围",
"en-tts": "Error: input out of range"
}
}

View file

@ -109,16 +109,16 @@
"en-tts": "Sign Xous update"
},
"mainmenu.set_rtc": {
"en": "Set UTC time",
"ja": "UTC 時間設定",
"zh": "设置UTC时间",
"en-tts": "Set UTC time"
"en": "Set time",
"ja": "時間設定",
"zh": "设置时间",
"en-tts": "Set time"
},
"mainmenu.set_tz": {
"en": "Set local timezone offset",
"en": "Set timezone",
"ja": "タイムゾーンを設定",
"zh": "设置本地时区",
"en-tts": "Set local timezone offset"
"en-tts": "Set timezone"
},
"mainmenu.pddb": {
"en": "PDDB Submenu",
@ -167,5 +167,107 @@
"ja": "Shellchat",
"zh": "外壳聊天",
"en-tts": "Shellchat"
},
"rtc.month": {
"en": "Enter month (1-12)",
"ja": "月(1-12)を入力してください。",
"zh": "输入月份 (1-12)",
"en-tts": "Enter month one through twelve"
},
"rtc.day": {
"en": "Enter day (1-31)",
"ja": "日数 (1-31) を入力してください。",
"zh": "输入日期 (1-31)",
"en-tts": "Enter day one through 31"
},
"rtc.year": {
"en": "Enter last two digits of year",
"ja": "西暦の下2桁を入力してください。",
"zh": "输入年份 (最后两位数)",
"en-tts": "Enter last two digits of year"
},
"rtc.hour": {
"en": "Enter hours in local timezone (0-23)",
"ja": "時間(0-23)を入力してください。",
"zh": "输入小时 (0-23)",
"en-tts": "Enter hours for local timezone as 24 hour format"
},
"rtc.minute": {
"en": "Enter minutes (0-59)",
"ja": "分(0-59)を入力してください。",
"zh": "输入分钟 (0-59)",
"en-tts": "Enter minutes"
},
"rtc.seconds": {
"en": "Enter seconds (0-59)",
"ja": "秒 (0-59) を入力してください。",
"zh": "输入秒数 (0-59)",
"en-tts": "Enter seconds"
},
"rtc.day_of_week": {
"en": "Select the day of week",
"ja": "曜日を選択してください。",
"zh": "[星期几]清单框",
"en-tts": "Select the day of week"
},
"rtc.monday": {
"en": "Monday",
"ja": "月曜日",
"zh": "星期一",
"en-tts": "Monday"
},
"rtc.tuesday": {
"en": "Tuesday",
"ja": "火曜日",
"zh": "星期二",
"en-tts": "Tuesday"
},
"rtc.wednesday": {
"en": "Wednesday",
"ja": "水曜日",
"zh": "星期三",
"en-tts": "Wednesday"
},
"rtc.thursday": {
"en": "Thursday",
"ja": "木曜日",
"zh": "星期四",
"en-tts": "Thursday"
},
"rtc.friday": {
"en": "Friday",
"ja": "金曜日",
"zh": "星期五",
"en-tts": "Friday"
},
"rtc.saturday": {
"en": "Saturday",
"ja": "土曜日",
"zh": "星期六",
"en-tts": "Saturday"
},
"rtc.sunday": {
"en": "Sunday",
"ja": "日曜日",
"zh": "星期日",
"en-tts": "Sunday"
},
"rtc.timezone": {
"en": "Please enter your local offset from UTC in hours (-12.0 to +14.0 hours).\nNote: Precursor does not yet track daylight savings.",
"ja": "UTCからのローカルオフセットを時間単位で入力してください(-12.0〜 + 14.0時間):",
"zh": "请以小时为单位输入您与 UTC 的本地偏移量(-12.0 到 +14.0 小时):",
"en-tts": "Please enter your local offset from UTC in hours (-12.0 to +14.0 hours):"
},
"rtc.integer_err": {
"en": "Error: entry was not numeric",
"ja": "エラー:エントリは数値ではありませんでした。",
"zh": "错误:输入不是数字",
"en-tts": "Error: entry was not numeric"
},
"rtc.range_err": {
"en": "Error: input out of range",
"ja": "エラー:入力が範囲外です。",
"zh": "错误:输入超出范围",
"en-tts": "Error: input out of range"
}
}

View file

@ -24,6 +24,7 @@ use chrono::prelude::*;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicBool, Ordering};
use std::io::Read;
#[cfg_attr(
not(any(target_os = "none", target_os = "xous")),
@ -590,6 +591,44 @@ fn xmain() -> ! {
continue;
}
pump_run.store(false, Ordering::Relaxed); // stop status updates while we do this
let mut tz_set_handle = pddb::Pddb::new();
let mut tz_set = false;
let mut tz_offset_ms = 0i64;
let maybe_tz_set_key = tz_set_handle.get(
time::TIME_SERVER_DICT,
time::TIME_SERVER_TZ_OFFSET,
None, false, false,
None,
None::<fn()>
).ok();
if let Some(mut tz_set_key) = maybe_tz_set_key {
let mut tz_buf = [0u8; 8];
if tz_set_key.read(&mut tz_buf).unwrap_or(0) == 8 {
tz_offset_ms = i64::from_le_bytes(tz_buf);
tz_set = true;
}
}
// note that we don't do an "else" here because we also want to catch the case of
// a key exists, but nothing was written to it (length of key was 0 or inappropriate)
if !tz_set {
let tz = modals.get_text(
t!("rtc.timezone", xous::LANG),
Some(tz_ux_validator), None
).expect("couldn't get timezone").as_str()
.parse::<f32>().expect("pre-validated input failed to re-parse!");
log::info!("got tz offset {}", tz);
tz_offset_ms = (tz * 3600.0 * 1000.0) as i64;
xous::send_message(timeserver_cid,
Message::new_scalar(
crate::time::TimeOp::SetTzOffsetMs.to_usize().unwrap(),
(tz_offset_ms >> 32) as usize,
(tz_offset_ms & 0xFFFF_FFFF) as usize,
0, 0,
)
).expect("couldn't set timezone");
}
let secs: u8;
let mins: u8;
let hours: u8;
@ -618,8 +657,6 @@ fn xmain() -> ! {
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got years {}", years);
modals.show_notification(t!("rtc.bodge", xous::LANG)).expect("couldn't show bodge note");
hours = modals.get_text(
t!("rtc.hour", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxHour.to_u32().unwrap())
@ -642,8 +679,8 @@ fn xmain() -> ! {
log::debug!("got seconds {}", secs);
log::info!("Setting time: {}/{}/{} {}:{}:{}", months, days, years, hours, mins, secs);
let new_dt = chrono::Utc.ymd(years as i32 + 2000, months as u32, days as u32)
.and_hms(hours as u32, mins as u32, secs as u32);
let new_dt = chrono::FixedOffset::east((tz_offset_ms / 1000) as i32).ymd(years as i32 + 2000, months as u32, days as u32)
.and_hms(hours as u32, mins as u32, secs as u32);
xous::send_message(timeserver_cid,
Message::new_scalar(
crate::time::TimeOp::SetUtcTimeMs.to_usize().unwrap(),

View file

@ -35,11 +35,11 @@ use num_traits::*;
pub const TIME_SERVER_PUBLIC: &'static [u8; 16] = b"timeserverpublic";
/// Dictionary for RTC settings.
const TIME_SERVER_DICT: &'static str = "sys.rtc";
pub(crate) const TIME_SERVER_DICT: &'static str = "sys.rtc";
/// This is the UTC offset from the current hardware RTC reading. This should be fixed once time is set.
const TIME_SERVER_UTC_OFFSET: &'static str = "utc_offset";
/// This is the offset from UTC to the display time zone. This can vary when the user changes time zones.
const TIME_SERVER_TZ_OFFSET: &'static str = "tz_offset";
pub(crate) const TIME_SERVER_TZ_OFFSET: &'static str = "tz_offset";
const CTL3: usize = 0;
const SECS: usize = 1;