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