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