improve date time

This commit is contained in:
lixianjing 2020-07-12 12:04:46 +08:00
parent f437b6921e
commit 3c46d6c1e2
6 changed files with 878 additions and 777 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,18 @@
# 最新动态
* 2020/07/12
* 完善 date\_time增加 date\_time\_get\_month\_name 和 date\_time\_get\_wday\_name。
* 2020/07/11
* 完善bidiwidget支持bidi属性。
* 完善hscroll_label对bidi的支持。
* 完善slide view indicator感谢朝泽提供补丁
* 完善 bidiwidget 支持 bidi 属性。
* 完善 hscroll_label bidi 的支持。
* 完善 slide view indicator感谢朝泽提供补丁
* 2020/07/10
* 完善tokenizer。
* 完善表达式增加iformat/fformat函数。
* 完善 tokenizer。
* 完善表达式,增加 iformat/fformat 函数。
* 完善资源管理器(感谢俊杰提供补丁)。
* 增加离线canvas感谢智明提供补丁
* 增加离线 canvas感谢智明提供补丁
* 2020/07/09
* 基本控件的文本支持双向排版 (Unicode Bidirectional Algorithm)

View File

@ -130,5 +130,27 @@ int32_t date_time_get_wday(uint32_t year, uint32_t month, uint32_t day) {
w = (d + 1 + 2 * m + 3 * (m + 1) / 5 + y + y / 4 + 5) % 7;
}
/*Sunday = 0*/
w = (w + 1) % 7;
return w;
}
static const char* s_en_month_names[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sept", "Oct", "Nov", "Dec"};
const char* date_time_get_month_name(uint32_t month) {
return_value_if_fail(month >= 1 && month <= 12, NULL);
return s_en_month_names[month - 1];
}
static const char* s_en_wday_names[] = {
"Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat",
};
const char* date_time_get_wday_name(uint32_t wday) {
return_value_if_fail(wday >= 0 && wday <= 6, NULL);
return s_en_wday_names[wday];
}

View File

@ -145,7 +145,7 @@ int32_t date_time_get_days(uint32_t year, uint32_t month);
/**
* @method date_time_get_wday
* (0-6)
* (0-6, Sunday = 0)
*
* @annotation ["scriptable", "static"]
* @param {uint32_t} year
@ -156,6 +156,28 @@ int32_t date_time_get_days(uint32_t year, uint32_t month);
*/
int32_t date_time_get_wday(uint32_t year, uint32_t month, uint32_t day);
/**
* @method date_time_get_month_name
* ()
*
* @annotation ["scriptable", "static"]
* @param {uint32_t} montn (1-12)
*
* @return {const char*} ()
*/
const char* date_time_get_month_name(uint32_t month);
/**
* @method date_time_get_wday_name
* ()
*
* @annotation ["scriptable", "static"]
* @param {uint32_t} wday (0-6, Sunday = 0)
*
* @return {const char*} ()
*/
const char* date_time_get_wday_name(uint32_t wday);
/**
* @method date_time_destroy
* date_time对象(使)

View File

@ -42,28 +42,42 @@ TEST(DateTime, days) {
ASSERT_EQ(date_time_get_days(2021, 12), 31);
}
TEST(DateTime, wday) {
ASSERT_EQ(date_time_get_wday(2020, 7, 8), 2);
ASSERT_EQ(date_time_get_wday(2020, 7, 9), 3);
ASSERT_EQ(date_time_get_wday(2020, 7, 10), 4);
ASSERT_EQ(date_time_get_wday(2020, 7, 11), 5);
ASSERT_EQ(date_time_get_wday(2020, 7, 12), 6);
ASSERT_EQ(date_time_get_wday(2020, 7, 13), 0);
ASSERT_EQ(date_time_get_wday(2020, 7, 14), 1);
ASSERT_EQ(date_time_get_wday(2014, 7, 8), 1);
ASSERT_EQ(date_time_get_wday(2014, 7, 9), 2);
ASSERT_EQ(date_time_get_wday(2014, 7, 10), 3);
ASSERT_EQ(date_time_get_wday(2014, 7, 11), 4);
ASSERT_EQ(date_time_get_wday(2014, 7, 12), 5);
ASSERT_EQ(date_time_get_wday(2014, 7, 13), 6);
ASSERT_EQ(date_time_get_wday(2014, 7, 14), 0);
ASSERT_EQ(date_time_get_wday(1000, 7, 8), 1);
ASSERT_EQ(date_time_get_wday(1000, 7, 9), 2);
ASSERT_EQ(date_time_get_wday(1000, 7, 10), 3);
ASSERT_EQ(date_time_get_wday(1000, 7, 11), 4);
ASSERT_EQ(date_time_get_wday(1000, 7, 12), 5);
ASSERT_EQ(date_time_get_wday(1000, 7, 13), 6);
ASSERT_EQ(date_time_get_wday(1000, 7, 14), 0);
TEST(DateTime, month_name) {
ASSERT_STREQ(date_time_get_month_name(1), "Jan");
ASSERT_STREQ(date_time_get_month_name(3), "Mar");
ASSERT_STREQ(date_time_get_month_name(8), "Aug");
ASSERT_STREQ(date_time_get_month_name(10), "Oct");
ASSERT_STREQ(date_time_get_month_name(12), "Dec");
}
TEST(DateTime, wday_name) {
ASSERT_STREQ(date_time_get_wday_name(0), "Sun");
ASSERT_STREQ(date_time_get_wday_name(1), "Mon");
ASSERT_STREQ(date_time_get_wday_name(6), "Sat");
}
TEST(DateTime, wday) {
ASSERT_EQ(date_time_get_wday(2020, 7, 8), 3);
ASSERT_EQ(date_time_get_wday(2020, 7, 9), 4);
ASSERT_EQ(date_time_get_wday(2020, 7, 10), 5);
ASSERT_EQ(date_time_get_wday(2020, 7, 11), 6);
ASSERT_EQ(date_time_get_wday(2020, 7, 12), 0);
ASSERT_EQ(date_time_get_wday(2020, 7, 13), 1);
ASSERT_EQ(date_time_get_wday(2020, 7, 14), 2);
ASSERT_EQ(date_time_get_wday(2014, 7, 8), 2);
ASSERT_EQ(date_time_get_wday(2014, 7, 9), 3);
ASSERT_EQ(date_time_get_wday(2014, 7, 10), 4);
ASSERT_EQ(date_time_get_wday(2014, 7, 11), 5);
ASSERT_EQ(date_time_get_wday(2014, 7, 12), 6);
ASSERT_EQ(date_time_get_wday(2014, 7, 13), 0);
ASSERT_EQ(date_time_get_wday(2014, 7, 14), 1);
ASSERT_EQ(date_time_get_wday(1000, 7, 8), 2);
ASSERT_EQ(date_time_get_wday(1000, 7, 9), 3);
ASSERT_EQ(date_time_get_wday(1000, 7, 10), 4);
ASSERT_EQ(date_time_get_wday(1000, 7, 11), 5);
ASSERT_EQ(date_time_get_wday(1000, 7, 12), 6);
ASSERT_EQ(date_time_get_wday(1000, 7, 13), 0);
ASSERT_EQ(date_time_get_wday(1000, 7, 14), 1);
}

View File

@ -34091,6 +34091,44 @@
"desc": "返回大于等于0表示周几(0-6),否则表示失败。"
}
},
{
"params": [
{
"type": "uint32_t",
"name": "montn",
"desc": "月份(1-12)。"
}
],
"annotation": {
"scriptable": true,
"static": true
},
"desc": "获取指定月份的英文名称(简写)。",
"name": "date_time_get_month_name",
"return": {
"type": "const char*",
"desc": "返回指定月份的英文名称(简写)。"
}
},
{
"params": [
{
"type": "uint32_t",
"name": "wday",
"desc": "星期几(0-6, Sunday = 0)。"
}
],
"annotation": {
"scriptable": true,
"static": true
},
"desc": "获取周几的英文名称(简写)。",
"name": "date_time_get_wday_name",
"return": {
"type": "const char*",
"desc": "返回指定周几的英文名称(简写)。"
}
},
{
"params": [
{