summaryrefslogtreecommitdiff
path: root/Build/source/libs/icu/icu-src/source/samples/datecal/cal.cpp
blob: f8c0ef500bc56438c722a868b53b3e0799de9102 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
*******************************************************************************
*
*   © 2016 and later: Unicode, Inc. and others.
*   License & terms of use: http://www.unicode.org/copyright.html
*
*******************************************************************************
*******************************************************************************
*
*   Copyright (C) 2002-2012, International Business Machines
*   Corporation and others.  All Rights Reserved.
*
*******************************************************************************
*/

#include "unicode/calendar.h"
#include "unicode/gregocal.h"
#include <stdio.h>

using namespace icu;

extern "C" void c_main();

void cpp_main()
{
  UErrorCode status = U_ZERO_ERROR;
  puts("C++ sample");
  GregorianCalendar* gc = new GregorianCalendar(status);
  if (U_FAILURE(status)) {
    puts("Couldn't create GregorianCalendar");
    return;
  }
  /* set up the date */
  gc->set(2000, UCAL_FEBRUARY, 26);
  gc->set(UCAL_HOUR_OF_DAY, 23);
  gc->set(UCAL_MINUTE, 0);
  gc->set(UCAL_SECOND, 0);
  gc->set(UCAL_MILLISECOND, 0);
  /* Iterate through the days and print it out. */
  for (int32_t i = 0; i < 30; i++) {
    /* print out the date. */
    /* You should use the DateFormat to properly format it */
    printf("year: %d, month: %d (%d in the implementation), day: %d\n",
           gc->get(UCAL_YEAR, status),
           gc->get(UCAL_MONTH, status) + 1,
           gc->get(UCAL_MONTH, status),
           gc->get(UCAL_DATE, status));
    if (U_FAILURE(status))
      {
        puts("Calendar::get failed");
        return;
      }
    /* Add a day to the date */
    gc->add(UCAL_DATE, 1, status);
    if (U_FAILURE(status)) {
      puts("Calendar::add failed");
      return;
    }
  }
  delete gc;
}
                

/* Creating and using text boundaries */
int main( void )
{
  puts("Date-Calendar sample program");

  cpp_main();

  c_main();

  return 0;
}