diff --git a/.gitattributes b/.gitattributes index 3ed4c24fef5..e44e44d32b9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -88,6 +88,9 @@ icu4c/source/i18n/persncal.cpp -text icu4c/source/i18n/persncal.h -text icu4c/source/i18n/reldtfmt.cpp -text icu4c/source/i18n/reldtfmt.h -text +icu4c/source/samples/tzdate/Makefile.in -text +icu4c/source/samples/tzdate/tzdate.c -text +icu4c/source/samples/tzdate/tzone -text icu4c/source/samples/ucnv/data02.bin -text icu4c/source/test/perf/charperf/CharPerf_r.pl -text icu4c/source/test/perf/convperf/ConvPerf_r.pl -text diff --git a/icu4c/source/configure b/icu4c/source/configure index 56a3891657a..b305de47d3a 100755 --- a/icu4c/source/configure +++ b/icu4c/source/configure @@ -8401,7 +8401,7 @@ then CXXFLAGS="$CXXFLAGS \$(THREADSCXXFLAGS)" fi - ac_config_files="$ac_config_files icudefs.mk Makefile data/icupkg.inc config/Makefile.inc data/Makefile stubdata/Makefile common/Makefile i18n/Makefile layout/Makefile layoutex/Makefile io/Makefile extra/Makefile extra/uconv/Makefile extra/scrptrun/Makefile tools/Makefile tools/ctestfw/Makefile tools/toolutil/Makefile tools/makeconv/Makefile tools/genrb/Makefile tools/genuca/Makefile tools/genccode/Makefile tools/gencmn/Makefile tools/gencnval/Makefile tools/genctd/Makefile tools/gennames/Makefile tools/gentest/Makefile tools/gennorm/Makefile tools/genprops/Makefile tools/gencase/Makefile tools/genbidi/Makefile tools/genpname/Makefile tools/genbrk/Makefile tools/gensprep/Makefile tools/icupkg/Makefile tools/icuswap/Makefile tools/pkgdata/Makefile tools/tzcode/Makefile test/Makefile test/testdata/Makefile test/testdata/pkgdata.inc test/hdrtst/Makefile test/intltest/Makefile test/cintltst/Makefile test/iotest/Makefile test/letest/Makefile samples/Makefile samples/date/Makefile samples/cal/Makefile samples/csdet/Makefile samples/layout/Makefile common/unicode/platform.h" + ac_config_files="$ac_config_files icudefs.mk Makefile data/icupkg.inc config/Makefile.inc data/Makefile stubdata/Makefile common/Makefile i18n/Makefile layout/Makefile layoutex/Makefile io/Makefile extra/Makefile extra/uconv/Makefile extra/scrptrun/Makefile tools/Makefile tools/ctestfw/Makefile tools/toolutil/Makefile tools/makeconv/Makefile tools/genrb/Makefile tools/genuca/Makefile tools/genccode/Makefile tools/gencmn/Makefile tools/gencnval/Makefile tools/genctd/Makefile tools/gennames/Makefile tools/gentest/Makefile tools/gennorm/Makefile tools/genprops/Makefile tools/gencase/Makefile tools/genbidi/Makefile tools/genpname/Makefile tools/genbrk/Makefile tools/gensprep/Makefile tools/icupkg/Makefile tools/icuswap/Makefile tools/pkgdata/Makefile tools/tzcode/Makefile test/Makefile test/testdata/Makefile test/testdata/pkgdata.inc test/hdrtst/Makefile test/intltest/Makefile test/cintltst/Makefile test/iotest/Makefile test/letest/Makefile samples/Makefile samples/date/Makefile samples/tzdate/Makefile samples/cal/Makefile samples/csdet/Makefile samples/layout/Makefile common/unicode/platform.h" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure diff --git a/icu4c/source/configure.in b/icu4c/source/configure.in index 4aa0d6f9d80..d5c202f79f5 100644 --- a/icu4c/source/configure.in +++ b/icu4c/source/configure.in @@ -1097,6 +1097,7 @@ AC_OUTPUT([icudefs.mk \ test/iotest/Makefile \ test/letest/Makefile \ samples/Makefile samples/date/Makefile \ + samples/tzdate/Makefile \ samples/cal/Makefile samples/csdet/Makefile samples/layout/Makefile \ common/unicode/platform.h]) diff --git a/icu4c/source/samples/Makefile.in b/icu4c/source/samples/Makefile.in index 03923fec8b8..5ff6056d877 100644 --- a/icu4c/source/samples/Makefile.in +++ b/icu4c/source/samples/Makefile.in @@ -19,7 +19,7 @@ include @platform_make_fragment@ ## Files to remove for 'make clean' CLEANFILES = *~ -SUBDIRS = date cal +SUBDIRS = date cal tzdate ALLSUBDIRS = break case csdet datefmt msgfmt numfmt props translit ucnv udata ufortune uresb ustring citer uciter8 ## List of phony targets diff --git a/icu4c/source/samples/tzdate/Makefile.in b/icu4c/source/samples/tzdate/Makefile.in new file mode 100644 index 00000000000..764b12d0d7c --- /dev/null +++ b/icu4c/source/samples/tzdate/Makefile.in @@ -0,0 +1,75 @@ +## Makefile.in for ICU - samples/tzdate +## Copyright (c) 1999-2007, International Business Machines Corporation and +## others. All Rights Reserved. + +## Source directory information + +srcdir=@srcdir@ +top_srcdir=@top_srcdir@ + +top_builddir = ../.. + +include $(top_builddir)/icudefs.mk + +## Build directory information +subdir = samples/tzdate + +## Extra files to remove for 'make clean' +CLEANFILES = *~ $(DEPS) + +## Target information +TARGET = tzdate$(EXEEXT) + +CPPFLAGS += -I$(top_builddir)/common -I$(top_srcdir)/common -I$(top_srcdir)/i18n +LIBS = $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) + +OBJECTS = tzdate.o + +DEPS = $(OBJECTS:.o=.d) + +## List of phony targets +.PHONY : all all-local install install-local clean clean-local \ +distclean distclean-local dist dist-local check check-local + +## Clear suffix list +.SUFFIXES : + +## List of standard targets +all: all-local +install: install-local +clean: clean-local +distclean : distclean-local +dist: dist-local +check: all check-local + +all-local: $(TARGET) + +install-local: all-local + +dist-local: + +clean-local: + test -z "$(CLEANFILES)" || $(RMV) $(CLEANFILES) + $(RMV) $(OBJECTS) $(TARGET) + +distclean-local: clean-local + $(RMV) Makefile + +check-local: + -$(INVOKE) ./$(TARGET) + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + +$(TARGET) : $(OBJECTS) + $(LINK.c) $(OUTOPT)$@ $^ $(LIBS) + $(POST_BUILD_STEP) + +ifeq (,$(MAKECMDGOALS)) +-include $(DEPS) +else +ifneq ($(patsubst %clean,,$(MAKECMDGOALS)),) +-include $(DEPS) +endif +endif diff --git a/icu4c/source/samples/tzdate/tzdate.c b/icu4c/source/samples/tzdate/tzdate.c new file mode 100644 index 00000000000..2aaad541dd8 --- /dev/null +++ b/icu4c/source/samples/tzdate/tzdate.c @@ -0,0 +1,147 @@ +/* +********************************************************************** +* Copyright (C) 1998-2007, International Business Machines +* Corporation and others. All Rights Reserved. +********************************************************************** +* +* File tzdate.c +* +* Author: Michael Ow +* +******************************************************************************* +*/ + +#include +#include +#include +#include + +#include "unicode/utypes.h" +#include "unicode/ustring.h" +#include "unicode/uclean.h" + +#include "unicode/ucnv.h" +#include "unicode/udat.h" +#include "unicode/ucal.h" + +#define SIZE 80 +#define OFFSET_MONTH 1 + +void getSystemCurrentTime(char* systime, int year, int month, int day, int useCurrentTime); +void getICUCurrentTime(char* icutime, int year, int month, int day, int useCurrentTime); +void printTime(char* systime, char* icutime); + +int main (int argc, char** argv) { + char* systime; + char* icutime; + int year, month, day; + int sysyear; + int useCurrentTime; + + sysyear = year = month = day = 0; + + year = atoi(argv[1]); + month = atoi(argv[2]); + day = atoi(argv[3]); + useCurrentTime = atoi(argv[4]); + + //format year for system time + sysyear = year - 1900; + + systime = malloc(sizeof(char) * SIZE); + icutime = malloc(sizeof(char) * SIZE); + + getSystemCurrentTime(systime, sysyear, month, day, useCurrentTime); + getICUCurrentTime(icutime, year, month, day, useCurrentTime); + + //print out the times if failed + if (strcmp(systime, icutime) != 0) { + printf("Failed\n"); + printTime(systime, icutime); + } + + return 0; +} + +void getICUCurrentTime(char* icutime, int year, int month, int day, int useCurrentTime) { + UDateFormat *fmt; + const UChar *tz = 0; + UChar *s = 0; + UDateFormatStyle style = UDAT_RELATIVE; + UErrorCode status = U_ZERO_ERROR; + int32_t len = 0; + + UCalendar *c; + c = NULL; + + fmt = udat_open(style, style, 0, tz, -1,NULL,0, &status); + + if (!useCurrentTime) { + c = ucal_open(0, -1, uloc_getDefault(), UCAL_TRADITIONAL, &status); + ucal_setDate(c, year, month - OFFSET_MONTH, day, &status); + + len = udat_format(fmt, ucal_getMillis(c, &status), 0, len, 0, &status); + + if (status == U_BUFFER_OVERFLOW_ERROR) + status = U_ZERO_ERROR; + + s = (UChar*) malloc(sizeof(UChar) * (len+1)); + + if(s == 0) + goto finish; + + udat_format(fmt, ucal_getMillis(c, &status), s, len + 1, 0, &status); + } else { + len = udat_format(fmt, ucal_getNow(), 0, len, 0, &status); + + if (status == U_BUFFER_OVERFLOW_ERROR) + status = U_ZERO_ERROR; + + s = (UChar*) malloc(sizeof(UChar) * (len+1)); + + if(s == 0) + goto finish; + + udat_format(fmt, ucal_getNow(), s, len + 1, 0, &status); + } + + if(U_FAILURE(status)) + goto finish; + + int i; + for(i = 0; i < len; i++) { + icutime[i] = (char)s[i]; + } + +finish: + if (c != NULL) { + ucal_close(c); + } + udat_close(fmt); + free(s); +} + +void getSystemCurrentTime(char* systime, int year, int month, int day, int useCurrentTime) { + time_t now; + struct tm ts; + + time(&now); + ts = *localtime(&now); + + if (!useCurrentTime){ + ts.tm_year = year; + ts.tm_mon = month - OFFSET_MONTH; + ts.tm_mday = day; + + now = mktime(&ts); + + ts = *localtime(&now); + } + + strftime(systime, sizeof(char) * 80, "%Y%m%d %I:%M %p", &ts); +} + +void printTime(char* systime, char* icutime) { + printf("System Time: %s\n", systime); + printf("ICU Time: %s\n", icutime); +} diff --git a/icu4c/source/samples/tzdate/tzone b/icu4c/source/samples/tzdate/tzone new file mode 100755 index 00000000000..f7f13660ecc --- /dev/null +++ b/icu4c/source/samples/tzdate/tzone @@ -0,0 +1,62 @@ +#!/usr/bin/perl +my $FILE = 'tzdate-log.txt'; +my $LIBRARY = '../../lib'; + +my @TZONE_RAW = `locate zoneinfo`; +my @TZONE; +my $index = 0; +my $USECURRENT = 0; +my $year = 0; +my $month = 0; +my $day = 0; + +open(MYFILE, ">$FILE"); + +if (scalar(@ARGV) == 3) { + ($year, $month, $day) = @ARGV; + print "We are using $month-$day-$year\n"; + print MYFILE "We are using $month-$day-$year\n"; +} else { + print "We are using the current time\n"; + print MYFILE "We are using the current time\n"; + $USECURRENT = 1; +} + +#filter out the time zones +foreach my $tzone (@TZONE_RAW) { + chomp($tzone); + if ($tzone =~ m|^/usr/share/zoneinfo/| && $tzone !~ m/tab$/) { + if (-e $tzone) { + $TZONE[$index] = substr($tzone, 20); + $index++; + } + } +} + +#go through each timezone and test +$count = 0; +$ENV{'LD_LIBRARY_PATH'} = $LIBRARY; + +print MYFILE "The following time zones had wrong results.\n"; + +foreach my $tzone (@TZONE) { + #set system time zone + $ENV{'TZ'} = "$tzone"; + + my @result = `./tzdate $year $month $day $USECURRENT`; + + #if the result is wrong print the time zone information to a log file + if (scalar(@result) > 0) { + print MYFILE "\n\nTIME ZONE: $tzone\n"; + print MYFILE "@result\n"; + $count++; + } +} + +print MYFILE "\nThe number of time zones with wrong results: $count\n"; +print "\nThe number of time zones with wrong results: $count\n"; + +close(MYFILE); + +print("\n\nGood Bye!\n"); +exit(0);