[i18ninfo] Add convert calendar menu 74/195874/4
authorHyunjee Kim <hj0426.kim@samsung.com>
Wed, 19 Dec 2018 06:00:08 +0000 (15:00 +0900)
committerHyunjee Kim <hj0426.kim@samsung.com>
Thu, 3 Jan 2019 00:47:50 +0000 (09:47 +0900)
Change-Id: Ibbce1aab743beca9655588a8b247526cb56fc7ca
Signed-off-by: Hyunjee Kim <hj0426.kim@samsung.com>
i18ninfo/i18ninfo.cpp
i18ninfo/i18ninfo_argp.h
packaging/capi-base-utils.spec

index 5a6f5a7..603aca8 100644 (file)
@@ -479,9 +479,15 @@ i18n_udate _time_convert(char *input_time)
        int year, month, day, hour, minute, second;
        struct tm result;
 
+       if (strlen(input_time) < 9) {
+               strcat(input_time, "000000");
+       }
        strptime(input_time, "%Y%m%d%H%M%S", &result);
+
        if (result.tm_year >= 100)
-               result.tm_year = result.tm_year%100 + 2000;
+               result.tm_year = result.tm_year % 100 + 2000;
+       else
+               result.tm_year = result.tm_year + 1900;
        PRINT_DEBUG_LOG("Date from strptime, year:%d month:%d day:%d hour:%d minute:%d second:%d.\n", result.tm_year, result.tm_mon+1, result.tm_mday, result.tm_hour, result.tm_min, result.tm_sec);
 
        /*create i18n_ucalendar_h */
@@ -1142,6 +1148,42 @@ static int __show_ubidi(char *input_text)
        return 0;
 }
 
+int __convert_lunar_calendar(char *input_time)
+{
+       i18n_ucalendar_h ucal_ch, ucal_greg;
+       i18n_ucalendar_create(NULL, NULL, "en@calendar=chinese", I18N_UCALENDAR_TRADITIONAL, &ucal_ch);
+       i18n_ucalendar_create(NULL, NULL, "en@calendar=gregorian", I18N_UCALENDAR_TRADITIONAL, &ucal_greg);
+
+       i18n_udate new_date;
+
+       if(input_time) {
+               printf(" - Input date : %s\n", input_time);
+               printf("****************************************\n");
+               new_date = _time_convert(input_time);
+               PRINT_DEBUG_LOG("_time_convert = %lf\n", new_date);
+               i18n_ucalendar_set_milliseconds(ucal_greg, new_date);
+       } else
+               i18n_ucalendar_get_milliseconds(ucal_greg, &new_date);
+
+       i18n_ucalendar_set_milliseconds(ucal_ch, new_date);
+
+       int month, day, year;
+       int month_ch, day_ch, year_ch;
+
+       i18n_ucalendar_get(ucal_greg, I18N_UCALENDAR_YEAR, &year);
+       i18n_ucalendar_get(ucal_greg, I18N_UCALENDAR_MONTH, &month);
+       i18n_ucalendar_get(ucal_greg, I18N_UCALENDAR_DATE, &day);
+
+       i18n_ucalendar_get(ucal_ch, I18N_UCALENDAR_YEAR, &year_ch);
+       i18n_ucalendar_get(ucal_ch, I18N_UCALENDAR_MONTH, &month_ch);
+       i18n_ucalendar_get(ucal_ch, I18N_UCALENDAR_DATE, &day_ch);
+
+       printf("Solar calendar) year:%d month:%d day:%d\n", year, month+1, day);
+       printf("Lunar calendar) year:%d month:%d day:%d\n", year_ch, month_ch+1, day_ch);
+
+       return 0;
+}
+
 #if (__TIZEN_VER >= 4)
 int32_t _ustring_append_n(i18n_uchar *dest, int32_t dest_length, const i18n_uchar *src, int32_t src_length)
 {
@@ -1863,6 +1905,18 @@ void testStringIter(char *input)
        }
 }
 
+void convertCalendar(char *input)
+{
+       int ret = 0;
+       printf("\n== Convert time to lunar calendar");
+       printf("\n****************************************\n");
+       ret = __convert_lunar_calendar(input);
+       if (ret == -1) {
+               printf("get lunar calendar failed\n");
+       }
+
+}
+
 int main(int argc, char *argv[])
 {
        struct arguments arguments = {0, };
@@ -1927,6 +1981,10 @@ int main(int argc, char *argv[])
                showUbidi(arguments.testTextArg);
        }
 
+       if (arguments.convertCalendar) {
+               convertCalendar(arguments.testTime);
+       }
+
 #if (__TIZEN_VER >= 4)
        if (arguments.testNumberConvert) {
                testNumberConvert(arguments.testNumberConvertArg);
index d07fe62..f5e00f8 100644 (file)
@@ -13,27 +13,29 @@ static char args_doc[] = "[Target] ...";
 
 
 static struct argp_option options[] = {
-       {"all",                                         'a', 0,                           0,                                    "Show all information and test" , 0 },
-       {"show-all-locale",                     'L', 0,                           0,                                    "Show all supported locales list", 0     },
-       {"show-lang-info",                      'I', 0,                           0,                                    "Show language information", 0  },
-       {"show-all-timezone",           'T', 0,                           0,                                    "Show all supported timezone list", 0    },
-       {"show-timezone",                       't', "TimezoneId",        OPTION_ARG_OPTIONAL,  "Show timezone", 0  },
-       {"show-tzdata-version",         'Z', 0,                           0,                                    "Show tzdata version", 0         },
-       {"show-date-format",            'D', 0,                           0,                                    "Show Date basic format", 0  },
-       {"test-datentime",                      'd', "DateTime",          OPTION_ARG_OPTIONAL,  "Date and time format test", 0  },
-       {"test-number-format",          'n', "Number",            0,                                    "Number format test", 0 },
-       {"test-number-symbol",          'N', 0,                           0,                                    "Number symbol test", 0 },
-       {"test-string",                         's', "Word",              OPTION_ARG_OPTIONAL,  "String test", 0  },
-       {"test-string-iter",            'S', "Type",              OPTION_ARG_OPTIONAL,  "String iteration test", 0       },
-       {"set-locale",                          'l', "locale",            0,                                    "Set specific locale", 0         },
-       {"print-ASCII",                         'p', 0,                           0,                                    "Print results as the ASCIIDoc Format", 0        },
-       {"show-ubidi",                          'b', 0,                           OPTION_ARG_OPTIONAL,  "Show examples of the Unicode Bidirectional Algorithm", 0        },
+       {"all",                                         'a',    0,                              0,                                              "Show all information and test",                                                0       },
+       {"show-all-locale",                     'L',    0,                              0,                                              "Show all supported locales list",                                              0       },
+       {"show-lang-info",                      'I',    0,                              0,                                              "Show language information",                                                    0       },
+       {"show-all-timezone",           'T',    0,                              0,                                              "Show all supported timezone list",                                             0       },
+       {"show-timezone",                       't',    "TimezoneId",   OPTION_ARG_OPTIONAL,    "Show timezone",                                                                                0       },
+       {"show-tzdata-version",         'Z',    0,                              0,                                              "Show tzdata version",                                                                  0       },
+       {"show-date-format",            'D',    0,                              0,                                              "Show Date basic format",                                                               0       },
+       {"test-datentime",                      'd',    "DateTime",             OPTION_ARG_OPTIONAL,    "Date and time format test",                                                    0       },
+       {"test-number-format",          'n',    "Number",               0,                                              "Number format test",                                                                   0       },
+       {"test-number-symbol",          'N',    0,                              0,                                              "Number symbol test",                                                                   0       },
+       {"test-string",                         's',    "Word",                 OPTION_ARG_OPTIONAL,    "String test",                                                                                  0       },
+       {"test-string-iter",            'S',    "Type",                 OPTION_ARG_OPTIONAL,    "String iteration test",                                                                0       },
+       {"set-locale",                          'l',    "locale",               0,                                              "Set specific locale",                                                                  0       },
+       {"print-ASCII",                         'p',    0,                              0,                                              "Print results as the ASCIIDoc Format",                                 0       },
+       {"show-ubidi",                          'b',    0,                              OPTION_ARG_OPTIONAL,    "Show examples of the Unicode Bidirectional Algorithm", 0       },
+       {"convert-calendar",            'e',    "Date",                 OPTION_ARG_OPTIONAL,    "Convert time to lunar calendar",                                               0       },
+
 #if (__TIZEN_VER >= 4)
-       {"test-number-converting",      'c', "Convert",           OPTION_ARG_OPTIONAL,  "Number converting test", 0     },
-       {"show-measure-unit",           'm', "Number",            OPTION_ARG_OPTIONAL,  "Show measure unit", 0   },
+       {"test-number-converting",      'c',    "Convert",              OPTION_ARG_OPTIONAL,    "Number converting test",                                                               0       },
+       {"show-measure-unit",           'm',    "Number",               OPTION_ARG_OPTIONAL,    "Show measure unit",                                                                    0       },
 #endif
 #if (__TIZEN_VER >= 5)
-       {"test-plural-rules",           'r', "input",             OPTION_ARG_OPTIONAL,  "Show Plural Rules", 0},
+       {"test-plural-rules",           'r',    "input",                OPTION_ARG_OPTIONAL,    "Show Plural Rules",                                                                    0       },
 #endif
        { 0 }
 };
@@ -54,6 +56,7 @@ struct arguments {
        int testStringIter;
        int printASCII;
        int showUbidi;
+       int convertCalendar;
 #if (__TIZEN_VER >= 4)
        int testNumberConvert;
        int showMeasureUnit;
@@ -71,6 +74,7 @@ struct arguments {
        char *testStringIterArg;
        char *setLocale;
        char *testTextArg;
+       char *testTime;
 #if (__TIZEN_VER >= 4)
        char *testNumberConvertArg;
        char *testInputNumArg;
@@ -182,6 +186,16 @@ parse_opt(int key, char *arg, struct argp_state *state)
                        state->next++;
                }
                break;
+       case 'e':
+               arguments->arg_flag = 18;
+               arguments->convertCalendar = 1;
+
+               nextArg = state->argv[state->next];
+               if (nextArg && *nextArg != '-') {
+                       arguments->testTime = nextArg;
+                       state->next++;
+               }
+               break;
 
 #if (__TIZEN_VER >= 4)
        case 'm':
index 137f55f..b987895 100755 (executable)
@@ -28,7 +28,7 @@ The base utils library for internationalization and localization (Development)
 %package -n i18ninfo
 License:    Apache-2.0
 Summary:    The Base Utils Tool
-Version:    1.1.1
+Version:    1.1.2
 Group:      Base
 Requires:      capi-base-utils