From 107ae577f84091e1657bb275f93d549765049497 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Mon, 23 Jun 2003 22:24:32 +0000 Subject: [PATCH] ICU-2672 new sample X-SVN-Rev: 12550 --- icu4c/source/samples/datecal/Makefile | 24 ++++++++++ icu4c/source/samples/datecal/cal.cpp | 67 +++++++++++++++++++++++++++ icu4c/source/samples/datecal/ccal.c | 55 ++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 icu4c/source/samples/datecal/Makefile create mode 100644 icu4c/source/samples/datecal/cal.cpp create mode 100644 icu4c/source/samples/datecal/ccal.c diff --git a/icu4c/source/samples/datecal/Makefile b/icu4c/source/samples/datecal/Makefile new file mode 100644 index 0000000000..a368cec70e --- /dev/null +++ b/icu4c/source/samples/datecal/Makefile @@ -0,0 +1,24 @@ +# Copyright (c) 2000-2003 IBM, Inc. and others +# sample code makefile + +# Usage: +# - configure, build, install ICU (make install) +# - make sure "icu-config" (in the ICU installed bin directory) is on +# the path +# - do 'make' in this directory + +#### definitions +# Name of your target +TARGET=datecal + +# All object files (C or C++) +OBJECTS=datecal.o cdatcal.o + +#### rules +# Load in standard makefile definitions +include ../defs.mk + +LDFLAGS += $(LDFLAGS_USTDIO) + +# the actual rules (this is a simple sample) +include ../rules.mk diff --git a/icu4c/source/samples/datecal/cal.cpp b/icu4c/source/samples/datecal/cal.cpp new file mode 100644 index 0000000000..f06538418f --- /dev/null +++ b/icu4c/source/samples/datecal/cal.cpp @@ -0,0 +1,67 @@ +/* +******************************************************************************* +* +* Copyright (C) 2002-2003, International Business Machines +* Corporation and others. All Rights Reserved. +* +******************************************************************************* +*/ + +#include "unicode/calendar.h" +#include "unicode/gregocal.h" +#include + +extern "C" { extern 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; +} + diff --git a/icu4c/source/samples/datecal/ccal.c b/icu4c/source/samples/datecal/ccal.c new file mode 100644 index 0000000000..09fd740854 --- /dev/null +++ b/icu4c/source/samples/datecal/ccal.c @@ -0,0 +1,55 @@ +/* +******************************************************************************* +* +* Copyright (C) 2002-2003, International Business Machines +* Corporation and others. All Rights Reserved. +* +******************************************************************************* +*/ + +#include "unicode/ucal.h" +#include + +void c_main() +{ + puts("----"); + puts("C Sample"); + +UErrorCode status = U_ZERO_ERROR; +int32_t i; +UCalendar *cal = ucal_open(NULL, -1, NULL, UCAL_GREGORIAN, &status); +if (U_FAILURE(status)) { + puts("Couldn't create GregorianCalendar"); + return; + } + // set up the date + ucal_set(cal, UCAL_YEAR, 2000); + ucal_set(cal, UCAL_MONTH, UCAL_FEBRUARY); /* FEBRUARY */ + ucal_set(cal, UCAL_DATE, 26); + ucal_set(cal, UCAL_HOUR_OF_DAY, 23); + ucal_set(cal, UCAL_MINUTE, 0); + ucal_set(cal, UCAL_SECOND, 0); + ucal_set(cal, UCAL_MILLISECOND, 0); + // Iterate through the days and print it out. + for (i = 0; i < 30; i++) { + // print out the date. + // You should use the udat_* API to properly format it + printf("year: %d, month: %d (%d in the implementation), day: %d\n", + ucal_get(cal, UCAL_YEAR, &status), + ucal_get(cal, UCAL_MONTH, &status) + 1, + ucal_get(cal, UCAL_MONTH, &status), + ucal_get(cal, UCAL_DATE, &status)); + if (U_FAILURE(status)) { + puts("Calendar::get failed"); + return; + } + // Add a day to the date + ucal_add(cal, UCAL_DATE, 1, &status); + if (U_FAILURE(status)) + { + puts("Calendar::add failed"); + return; + } + } + ucal_close(cal); +}