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