]> git.saurik.com Git - apple/icu.git/blame - icuSources/samples/datecal/cal.cpp
ICU-64260.0.1.tar.gz
[apple/icu.git] / icuSources / samples / datecal / cal.cpp
CommitLineData
374ca955
A
1/*
2*******************************************************************************
3*
f3c0d7a5
A
4* © 2016 and later: Unicode, Inc. and others.
5* License & terms of use: http://www.unicode.org/copyright.html#License
6*
7*******************************************************************************
8*******************************************************************************
9*
51004dcb 10* Copyright (C) 2002-2012, International Business Machines
374ca955
A
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
51004dcb 20extern "C" void c_main();
374ca955
A
21
22void 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 */
63int main( void )
64{
65 puts("Date-Calendar sample program");
66
67 cpp_main();
68
69 c_main();
70
71 return 0;
72}
73