1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru******************************************************************************* 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Copyright (C) 2002-2003, International Business Machines 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Corporation and others. All Rights Reserved. 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru******************************************************************************* 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ucal.h" 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdio.h> 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid c_main() 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru puts("----"); 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru puts("C Sample"); 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUErrorCode status = U_ZERO_ERROR; 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint32_t i; 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCalendar *cal = ucal_open(NULL, -1, NULL, UCAL_GREGORIAN, &status); 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruif (U_FAILURE(status)) { 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru puts("Couldn't create GregorianCalendar"); 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* set up the date */ 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucal_set(cal, UCAL_YEAR, 2000); 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucal_set(cal, UCAL_MONTH, UCAL_FEBRUARY); /* FEBRUARY */ 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucal_set(cal, UCAL_DATE, 26); 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucal_set(cal, UCAL_HOUR_OF_DAY, 23); 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucal_set(cal, UCAL_MINUTE, 0); 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucal_set(cal, UCAL_SECOND, 0); 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucal_set(cal, UCAL_MILLISECOND, 0); 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Iterate through the days and print it out. */ 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (i = 0; i < 30; i++) { 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* print out the date. */ 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* You should use the udat_* API to properly format it */ 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru printf("year: %d, month: %d (%d in the implementation), day: %d\n", 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucal_get(cal, UCAL_YEAR, &status), 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucal_get(cal, UCAL_MONTH, &status) + 1, 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucal_get(cal, UCAL_MONTH, &status), 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucal_get(cal, UCAL_DATE, &status)); 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru puts("Calendar::get failed"); 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Add a day to the date */ 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucal_add(cal, UCAL_DATE, 1, &status); 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru puts("Calendar::add failed"); 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucal_close(cal); 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 56