Assignments | Class Photo | Course Home | Documentation | Schedule & Lecture Notes | Submit

Saint Louis University

Computer Science 290
Object-Oriented Software Design

Michael Goldwasser

Fall 2008

Dept. of Math & Computer Science

Assignment 02

Calendar

Contents:


Overview

Topic: Calendar
Related Reading: Ch. 3 of text
Due: Thursday, 25 September 2008, 11:59pm
Tuesday, 30 September 2008, 11:59pm

The goal of this assignment is to provide experience in using libraries that provide internationalization for dates and calendars.


Collaboration Policy

For this assignment, you must work individually.

Please make sure you adhere to the policies on academic integrity in this regard.


Calendars and Internationalization

The most commonly used is the Gregorian calendar (e.g. January, February, March, ...). As an example, here is how October 2008 of the Gregorian calendar is typically displayed in the United States:

October 2008
Sun Mon Tue Wed Thu Fri Sat
              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

However, other calendars are used in some cultures, such as the Islamic Calendar, Hebrew Calendar, Chinese Calendar, and so on. For example, here is a typical month of the Hebrew Calendar (as it would be displayed in the United States).

Heshvan 5769
Sun Mon Tue Wed Thu Fri Sat
                  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
Here is a typical month of the Islamic calendar (as it would be displayed in the United States)
Shawwal 1429
Sun Mon Tue Wed Thu Fri Sat
                  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
Note: in the case of the Islamic calendar, there are two different sets of conventions. The traditional religious calendar has lunar months whose beginings depend upon local sightings of the new moon. Because those sightings are less predictable and change from location to location, there is also an Islamic civil calendar based upon a predictable pattern for the month beginnings. The example of Shawwal above is actually the civic version of that month.

Locales

A separate factor when displaying a calendar is the locale for which the calendar is to be viewed. For example, the Gregorian calendar as displayed in the United States is different than the Gregorian calendar as it might be displayed in France, or Spain, or Israel.

The issues are twofold. First, the names of the months and days of the week typically differ across languages. Secondly, different countries have different conventions for what is considered the first day of the week when displaying a calendar. For example, in the United States a week is displayed with Sunday being the first day of the week, yet in much of Europe Monday is displayed in the leftmost column as the first day of the week, with that week ending on Sunday.

As an example, here is a typical display of October 2008 in Spain:

octubre 2008
lun mar mié jue vie sáb dom
          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

Here is an example of the same month, as displayed in Somalia; notice that the first day of the displayed week is Saturday.

Bisha Tobnaad 2008
Sab Axa Isn Sal Arb Kha Jim
                  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

It should be possible to combine any of the calendar choices with any of the local conventions for a particular locale. As further examples, the following display a Hebrew month and an Islamic (civil) month, as it might appear in France:

Hesvan 5769
lun. mar. mer. jeu. ven. sam. dim.
                  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
Chaououal 1429
lun. mar. mer. jeu. ven. sam. dim.
                  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


Internationalization in Java

The standard Java libraries contains some support for calendars and internationalization. Most notably, they provide an abstract class java.util.Calendar that gives a more general structure for a world calendar, when specialized for display in a specific locale. This class provides support for the rules for advancing from day to day and month to month in a calendar. It also provides methods such as getFirstDayOfWeek() to determine which weekday is considered the first. It also provides accessors to determine variables such as how many days are in a given month, or how many months are in a given year.

Java also provides the java.util.Locale object to identify and encapsulate conventions of a particular world locale. The classes java.text.DateFormat and java.text.DateFormatSymbols can be used to generate appropriate strings for displaying dates, or getting full or abbreviated names for months in the year and days in the week.

However, Java's support for calendars is limited. Although the abstract Calendar class is designed to handle a more general view of calendars, the only underlying implementation that they provide is the GregorianCalendar. This means that it is possible to typeset the Gregorian calendar in a variety of world locales, there is not support for other calendars such as the Hebrew, Islamic, Japanese, or Chinese calendars.

To provide greater support for this assignment, we will rely upon an outside library known as the International Components for Unicode (ICU), as described in the next section.


Using the ICU Libraries

The ICU is an open-source project supported by IBM in an effort to provide greater internationalization for global software. It is available for C/C++ and Java. We will be using the Java API named ICU4J.

Access to the library: We have installed the icu4j library for local use at turing:/usr/share/java/icu4j.jar. If you would like to work on this project on some other system (other than remote access to turing), you will need to copy that file on your local system.

Using with Eclipse: After creating a new project, you will need to add icu4j to the path for your project. Select the project from the Package Explorer and then select Properties from the File menu (or from the pop-up menu when clicking the mouse). Goto the Java Build Path section, switch to the Libraries tab, and click the button Add External JARs. Enter /usr/share/java/icu4j.jar as the Location and click OK.

Using directly with JDK: When compiling your project, you will need to add the library to the classpath, using the command

javac -cp .:/usr/share/java/icu4j.jar YourProgram.java
You will also need to adjust the classpath when executing your program, as follows:
java -cp .:/usr/share/java/icu4j.jar YourProgram

Documentation: the ICU4J API will be a necessary reference for this assignment.

Overview of Relevant Components: The ICU libraries are modeled very closely after corresponding components in the standard Java libraries, but the ICU classes are not formally extensions of Java's classes. The most important classes for this assignment include:


Formal Program Requirements

You should write a program that offers the user a choice of locale, a choice of calendar, and a choice of year, and then produces an appropriate representation of the given year (see Sample Output section below).

For the choice of locales, you should offer a menu of all available locales on the system. As an example, on turing the list of available locales begins as

Afrikaans
Afrikaans (South Africa)
Amharic
Amharic (Ethiopia)
Arabic
...
We suggest numbering each of these and allowing the user to select a locale by indicating the associated number.

For the choice of calendar, you should explicitly offer the choice of either Gregorian, Hebrew, or Islamic (civil).


Sample Output

We have prepared samples of six different calendars, each displayed in three different locales. The six years employed are:

Each of these calendars is displayed in the following three locales:


Artifacts to Submit

Your assignment should be submitted electronically (details on the submission process).


Extra Credit

In the main part of the assignment, we demonstrated calendars as shown in several different locales. But we intentionally avoided languages that are read right-to-left (e.g, Hebrew, Arabic). Ideally, a good internationalized package should support those locales gracefully. That is true of ICU, but it takes additional care.

Let's begin by looking at what might go wrong for example when using the Israel locale. The conventional first day of a week in Israel is Sunday and is represented using the character aleph (א). That is followed by Monday (ב), and so on, leading to column labels:

 א  ב  ג  ד  ה  ו  ש
Chance are, if your original program were to use the Israel locale, you would find these labels displayed appropriately. The Hebrew column labels are correctly reported by DateFormatSymbol, and when your print them starting with ב, that line is automatically displayed from right-to-left because such an ordering is encoded as part of the Unicode characters.

The problem is that other lines of the calendar would be displayed from left-to-right using standard numerals. For example, an errant view of the Gregorian October 2008 might appear as:

אוקטובר 2008
 א  ב  ג  ד  ה  ו  ש
          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
Notice that the column headers were displayed from right-to-left with the rightmost column labeled aleph (א) representing Sunday on this calendar. Yet the first Sunday in October 2008 is the 5th. If the dates were properly arranged in columns, the calendar would be typeset as
אוקטובר 2008
 א  ב  ג  ד  ה  ו  ש
 4  3  2  1
11 10  9  8  7  6  5
18 17 16 15 14 13 12
25 24 23 22 21 20 19
   31 30 29 28 27 26

Your Challenge: Update your original program so that it produces a calendar with dates arranged right-to-left for appropriate locales, while still working properly for left-to-right locales.

By the way, we are not sure how to accomplish this in a clean, transparent way. Hence, its extra credit!


Michael Goldwasser
CSCI 290, Fall 2008
Last modified: Wednesday, 29 October 2008
Assignments | Class Photo | Course Home | Documentation | Schedule & Lecture Notes | Submit