1 Copyright (c) 2002-2010, International Business Machines Corporation and others. All Rights Reserved. 2 3 4 IMPORTANT: 5 6 This sample was originally intended as an exercise for the ICU Workshop (September 2000). 7 The code currently provided in the solution file is the answer to the exercises, each step can still be found in the 'answers' subdirectory. 8 9 10 11 12 http://www.icu-project.org/docs/workshop_2000/agenda.html 13 14 Day 2: September 12th 2000 15 Pre-requisites: 16 1. All the hardware and software requirements from Day 1. 17 2. Attended or fully understand Day 1 material. 18 3. Read through the ICU user's guide at 19 http://www.icu-project.org/userguide/. 20 21 #Date/Time/Number Formatting Support 22 9:30am - 10:30am 23 Alan Liu 24 25 Topics: 26 1. What is the date/time support in ICU? 27 2. What is the timezone support in ICU? 28 3. What kind of formatting and parsing support is available in ICU, i.e. 29 NumberFormat, DateFormat, MessageFormat? 30 31 32 INSTRUCTIONS 33 ------------ 34 35 36 This exercise was first developed and tested on ICU release 1.6.0, Win32, 37 Microsoft Visual C++ 6.0. It should work on other ICU releases and 38 other platforms as well. 39 40 MSVC: 41 Open the file "msgfmt.sln" in Microsoft Visual C++. 42 43 Unix: 44 - Build and install ICU with a prefix, for example '--prefix=/home/srl/ICU' 45 - Set the variable ICU_PREFIX=/home/srl/ICU and use GNU make in 46 this directory. 47 - You may use 'make check' to invoke this sample. 48 49 PROBLEMS 50 -------- 51 52 Problem 0: 53 54 Set up the program, build it, and run it. To start with, the 55 program prints out the word "Message". 56 57 Problem 1: Basic Message Formatting (Easy) 58 59 Use a MessageFormat to create a message that prints out "Received 60 <n> argument(s) on <d>.", where n is the number of command line 61 arguments (use argc-1), and d is the date (use Calendar::getNow()). 62 63 HINT: Your message pattern should have a "number" element and a 64 "date" element, and you will need to use Formattable. 65 66 Problem 2: ChoiceFormat (Medium) 67 68 We can do better than "argument(s)". Instead, we can display more 69 idiomatic strings, such as "no arguments", "one argument", "two 70 arguments", and for higher values, we can use a number format. 71 72 This kind of value-based switching is done using a ChoiceFormat. 73 However, you seldom needs to create a ChoiceFormat by itself. 74 Instead, most of the time you will supply the ChoiceFormat pattern 75 within a MessageFormat pattern. 76 77 Use a ChoiceFormat pattern within the MessageFormat pattern, instead 78 of the "number" element, to display more idiomatic strings. 79 80 EXTRA: Embed a number element within the choice element to handle 81 values greater than two. 82 83 84 ANSWERS 85 ------- 86 87 The exercise includes answers. These are in the "answers" directory, 88 and are numbered 1, 2, etc. 89 90 If you get stuck and you want to move to the next step, copy the 91 answers file into the main directory in order to proceed. E.g., 92 "main_1.cpp" contains the original "main.cpp" file. "main_2.cpp" 93 contains the "main.cpp" file after problem 1. Etc. 94 95 96 Have fun! 97