Created
November 25, 2025 00:54
-
-
Save catamorphism/ce7e35d5019395471a65d4e0766a4611 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define U_DISABLE_RENAMING 1 | |
| #include <stdio.h> | |
| #include "unicode/utypes.h" | |
| #include "unicode/uenum.h" | |
| #include "unicode/uloc.h" | |
| #include "unicode/localpointer.h" | |
| #include "unicode/ucal.h" | |
| #include "unicode/calendar.h" | |
| using namespace icu; | |
| #define CHECK_ERROR if (U_FAILURE(errorCode)) { \ | |
| printf("%s\n", u_errorName(errorCode)); \ | |
| return false; \ | |
| } | |
| bool testCalendar(int32_t y, int32_t m, int32_t d) { | |
| UErrorCode errorCode = U_ZERO_ERROR; | |
| LocalPointer<Calendar> cal(Calendar::createInstance(Locale("zh-CN@calendar=chinese"), errorCode)); | |
| LocalPointer<Calendar> cal2(Calendar::createInstance(Locale("en-US@calendar=gregorian"), errorCode)); | |
| CHECK_ERROR | |
| cal2->set(y, m, d); | |
| time_t time = cal2->getTime(errorCode); | |
| CHECK_ERROR | |
| cal->setTime(time, errorCode); | |
| int32_t year = cal->get(UCAL_YEAR, errorCode); | |
| CHECK_ERROR | |
| int32_t extendedYear = cal->get(UCAL_EXTENDED_YEAR, errorCode); | |
| CHECK_ERROR | |
| int32_t month = cal->get(UCAL_MONTH, errorCode); | |
| CHECK_ERROR | |
| const char* monthCode = cal->getTemporalMonthCode(errorCode); | |
| printf("%d %d %d %s\n", year, extendedYear, month + 1, monthCode); | |
| int32_t gregorianYear = cal2->get(UCAL_YEAR, errorCode); | |
| CHECK_ERROR | |
| int32_t gregorianMonth = cal2->get(UCAL_MONTH, errorCode); | |
| CHECK_ERROR | |
| const char* gregorianMonthCode = cal2->getTemporalMonthCode(errorCode); | |
| CHECK_ERROR | |
| printf(" Gregorian: %d %d %s\n", gregorianYear, gregorianMonth + 1, gregorianMonthCode); | |
| return true; | |
| } | |
| int main() { | |
| bool result = true; | |
| for (int32_t month = 0; month < 12; month++) | |
| result &= testCalendar(1987, month, 15); | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment