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-2012, International Business Machines
11 * Corporation and others. All Rights Reserved.
12 *
13 *******************************************************************************
14 */
15
16 #include "unicode/calendar.h"
17 #include "unicode/gregocal.h"
18 #include <stdio.h>
19
20 extern "C" void c_main();
21
cpp_main()22 void cpp_main()
23 {
24 UErrorCode status = U_ZERO_ERROR;
25 puts("C++ sample");
26 GregorianCalendar* gc = new GregorianCalendar(status);
27 if (U_FAILURE(status)) {
28 puts("Couldn't create GregorianCalendar");
29 return;
30 }
31 /* set up the date */
32 gc->set(2000, UCAL_FEBRUARY, 26);
33 gc->set(UCAL_HOUR_OF_DAY, 23);
34 gc->set(UCAL_MINUTE, 0);
35 gc->set(UCAL_SECOND, 0);
36 gc->set(UCAL_MILLISECOND, 0);
37 /* Iterate through the days and print it out. */
38 for (int32_t i = 0; i < 30; i++) {
39 /* print out the date. */
40 /* You should use the DateFormat to properly format it */
41 printf("year: %d, month: %d (%d in the implementation), day: %d\n",
42 gc->get(UCAL_YEAR, status),
43 gc->get(UCAL_MONTH, status) + 1,
44 gc->get(UCAL_MONTH, status),
45 gc->get(UCAL_DATE, status));
46 if (U_FAILURE(status))
47 {
48 puts("Calendar::get failed");
49 return;
50 }
51 /* Add a day to the date */
52 gc->add(UCAL_DATE, 1, status);
53 if (U_FAILURE(status)) {
54 puts("Calendar::add failed");
55 return;
56 }
57 }
58 delete gc;
59 }
60
61
62 /* Creating and using text boundaries */
main(void)63 int main( void )
64 {
65 puts("Date-Calendar sample program");
66
67 cpp_main();
68
69 c_main();
70
71 return 0;
72 }
73
74