1 /*
2 *******************************************************************************
3 *
4 * © 2016 and later: Unicode, Inc. and others.
5 * License & terms of use: http://www.unicode.org/copyright.html
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 using namespace icu;
21
22 extern "C" void c_main();
23
cpp_main()24 void cpp_main()
25 {
26 UErrorCode status = U_ZERO_ERROR;
27 puts("C++ sample");
28 GregorianCalendar* gc = new GregorianCalendar(status);
29 if (U_FAILURE(status)) {
30 puts("Couldn't create GregorianCalendar");
31 return;
32 }
33 /* set up the date */
34 gc->set(2000, UCAL_FEBRUARY, 26);
35 gc->set(UCAL_HOUR_OF_DAY, 23);
36 gc->set(UCAL_MINUTE, 0);
37 gc->set(UCAL_SECOND, 0);
38 gc->set(UCAL_MILLISECOND, 0);
39 /* Iterate through the days and print it out. */
40 for (int32_t i = 0; i < 30; i++) {
41 /* print out the date. */
42 /* You should use the DateFormat to properly format it */
43 printf("year: %d, month: %d (%d in the implementation), day: %d\n",
44 gc->get(UCAL_YEAR, status),
45 gc->get(UCAL_MONTH, status) + 1,
46 gc->get(UCAL_MONTH, status),
47 gc->get(UCAL_DATE, status));
48 if (U_FAILURE(status))
49 {
50 puts("Calendar::get failed");
51 return;
52 }
53 /* Add a day to the date */
54 gc->add(UCAL_DATE, 1, status);
55 if (U_FAILURE(status)) {
56 puts("Calendar::add failed");
57 return;
58 }
59 }
60 delete gc;
61 }
62
63
64 /* Creating and using text boundaries */
main(void)65 int main( void )
66 {
67 puts("Date-Calendar sample program");
68
69 cpp_main();
70
71 c_main();
72
73 return 0;
74 }
75
76