Skip to content

Instantly share code, notes, and snippets.

@catamorphism
Created December 8, 2025 22:43
Show Gist options
  • Select an option

  • Save catamorphism/358762523ea082f600a51f67afee5d15 to your computer and use it in GitHub Desktop.

Select an option

Save catamorphism/358762523ea082f600a51f67afee5d15 to your computer and use it in GitHub Desktop.
#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> chinese(Calendar::createInstance(Locale("zh-CN@calendar=chinese"), errorCode));
CHECK_ERROR
chinese->set(UCAL_EXTENDED_YEAR, y);
chinese->set(UCAL_MONTH, m);
chinese->set(UCAL_DATE, d);
int32_t chineseExtendedYear = y;
int32_t dayOfYear = 1;
const char* chineseMonthCode;
int32_t chineseDay = 1;
while (chineseExtendedYear == y) {
printf("%d: %d-%s-%d\n", dayOfYear, chineseExtendedYear, chineseMonthCode, chineseDay);
chinese->add(UCAL_DATE, 1, errorCode);
CHECK_ERROR
chineseExtendedYear = chinese->get(UCAL_EXTENDED_YEAR, errorCode);
chineseMonthCode = chinese->getTemporalMonthCode(errorCode);
chineseDay = chinese->get(UCAL_DATE, errorCode);
CHECK_ERROR
dayOfYear++;
};
return true;
}
int main() {
bool result = true;
result &= testCalendar(2026, 0, 1);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment