127f654740f2a26ad62a5c155af9199af9e69b889clairehoCopyright (c) 2002-2010, International Business Machines Corporation and others. All Rights Reserved.
227f654740f2a26ad62a5c155af9199af9e69b889claireho
327f654740f2a26ad62a5c155af9199af9e69b889clairehoIMPORTANT:
427f654740f2a26ad62a5c155af9199af9e69b889claireho
527f654740f2a26ad62a5c155af9199af9e69b889clairehoThis sample was originally intended as an exercise for the ICU Workshop (September 2000).
627f654740f2a26ad62a5c155af9199af9e69b889clairehoThe code currently provided in the solution file is the answer to the exercises, each step can still be found in the 'answers' subdirectory.
727f654740f2a26ad62a5c155af9199af9e69b889claireho
827f654740f2a26ad62a5c155af9199af9e69b889claireho
927f654740f2a26ad62a5c155af9199af9e69b889claireho
10b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru** Workshop homepage is:  
11b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  http://www.icu-project.org/docs/workshop_2000/agenda.html
12b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
13b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  #Date/Time/Number Formatting Support
14b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  9:30am - 10:30am
15b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  Alan Liu
16b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
17b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  Topics:
18b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  1. What is the date/time support in ICU?
19b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  2. What is the timezone support in ICU?
20b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  3. What kind of formatting and parsing support is available in ICU, i.e.
21b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  NumberFormat, DateFormat, MessageFormat?
22b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
23b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
24b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruINSTRUCTIONS
25b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru------------
26b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
27b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruThis exercise was first developed and tested on ICU release 1.6.0, Win32,
28b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruMicrosoft Visual C++ 6.0.  It should work on other ICU releases and
29b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruother platforms as well.
30b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
31b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru MSVC:
32b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru   Open the file "datefmt.sln" in Microsoft Visual C++.
33b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
34b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru Unix:
35b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru   - Build and install ICU with a prefix, for example '--prefix=/home/srl/ICU'
36b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru   - Set the variable  ICU_PREFIX=/home/srl/ICU and use GNU make in 
37b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        this directory.
38b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru   - You may use 'make check' to invoke this sample.
39b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
40b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruPROBLEMS
41b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru--------
42b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
43b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruProblem 0:
44b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
45b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  Set up the program, build it, and run it.  To start with, the
46b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  program prints out a list of languages.
47b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
48b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruProblem 1: Basic Date Formatting (Easy)
49b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
50b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  Create a calendar, and use it to get the UDate for June 4, 1999,
51b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  0:00 GMT (or any date of your choosing).  You will have to create a
52b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  TimeZone (use the createZone() function already defined in main.cpp)
53b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  and a Calendar object, and make the calendar use the time zone.
54b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
55b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  Once you have the UDate, create a DateFormat object in each of the
56b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  languages in the LANGUAGE array, and display the date in that
57b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  language.  Use the DateFormat::createDateInstance() method to create
58b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  the date formatter.
59b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
60b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruProblem 2: Date Formatting, Specific Time Zone (Medium)
61b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
62b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  To really localize a time display, one can also specify the time
63b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  zone in which the time should be displayed.  For each language,
64b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  also create different time zones from the TIMEZONE list.
65b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
66b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  To format a date with a specific calendar and zone, you must deal with
67b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  three objects: a DateFormat, a Calendar, and a TimeZone.  Each object
68b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  must be linked to another in correct sequence:  The Calendar must use
69b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  the TimeZone, and the DateFormat must use the Calendar.
70b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
71b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DateFormat  =uses=>  Calendar  =uses=>  TimeZone
72b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
73b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  Use either setFoo() or adoptFoo() methods, depending on where you
74b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  want to have ownership.
75b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
76b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  NOTE: It's not always desirable to change the time to a local time
77b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  zone before display.  For instance, if some even occurs at 0:00 GMT
78b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  on the first of the month, it's probably clearer to just state that.
79b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  Stating that it occurs at 5:00 PM PDT on the day before in the
80b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  summer, and 4:00 PM PST on the day before in the winter will just
81b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  confuse the issue.
82b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
83b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
84b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruNOTES
85b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru-----
86b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
87b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruTo see a list of system TimeZone IDs, use the TimeZone::create-
88b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruAvailableIDs() methods.  Alternatively, look at the file
89b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruicu/docs/tz.htm.  This has a hyperlinked list of current system zones.
90b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
91b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
92b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruANSWERS
93b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru-------
94b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
95b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruThe exercise includes answers.  These are in the "answers" directory,
96b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruand are numbered 1, 2, etc.
97b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
98b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruIf you get stuck and you want to move to the next step, copy the
99b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruanswers file into the main directory in order to proceed.  E.g.,
100b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru"main_1.cpp" contains the original "main.cpp" file.  "main_2.cpp"
101b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querucontains the "main.cpp" file after problem 1.  Etc.
102b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
103b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
104b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruHave fun!
105