Date/Time/Number Formatting - PowerPoint PPT Presentation

About This Presentation
Title:

Date/Time/Number Formatting

Description:

Reflects different local conventions: time zone, definition of the week, calendar ... Stored as absolute time independent of local time zones (GMT-based) ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 28
Provided by: helen2
Learn more at: https://icu-project.org
Category:

less

Transcript and Presenter's Notes

Title: Date/Time/Number Formatting


1
Date/Time/Number Formatting
  • Alan Liu
  • Globalization Center of Competency
  • IBM Emerging Technology Center

2
  • Overview

3
The Problem
  • Display a date in different languages
  • English Friday, June 4, 1999
  • German Freitag, 4. Juni 1999
  • French vendredi 4 juin 1999

4
The Problem
  • Display a date in different languages
  • Convert a time between local time zones
  • Los Angeles June 3, 1999 500 PM PDT
  • New York June 3, 1999 800 PM EDT
  • Paris June 4, 1999 200 AM CEST

5
The Problem
  • Display a date in different languages
  • Convert a time between local time zones
  • Handle daylight savings time
  • Sat. Oct. 28, 2000 300 PM PDT 24 hours
  • Sun. Oct. 29, 2000 200 PM PST

6
The Problem
  • These problems boil down to
  • Formatting
  • Parsing
  • Data conversion
  • These operations apply to different data types
  • Dates and times
  • Numbers, including currency amounts
  • Messages

7
Formatting and Parsing
  • Formatting conversion of binary data to text
  • Parsing conversion of text to binary data
  • Different locales use different text to represent
    the same piece of binary data

8
Data Conversion
  • In different locales, not only the form but also
    the value of displayed data may change
  • Reflects different local conventions time zone,
    definition of the week, calendar
  • Applies only to dates and times

9
Data Conversion
  • Displayed data values differ depending on the
    locale
  • Underlying binary data does not change
  • Displayed data Calendar fields
  • Underlying data UDate scalar

10
Data Conversion
  • Conversion happens implicitly during formatting
    and parsing
  • Conversion can also be done explicitly

11
  • Date and Time

12
Date and Time
  • Date and time stored together as a scalar
  • Resolution of 1 millisecond
  • Range roughly 70,000 BC to 70,000 AD
  • Stored as absolute time independent of local time
    zones (GMT-based)

13
Date and Time
  • Extensible calendar system
  • Rule-based time zones with built-in data for all
    modern international zones (over 400)
  • Rule-based date format with built-in data for
    many locales (over 140)

14
Date and Time Components
  • UDate GMT-based date and time (ms)
  • Calendar Convert UDate to/from fields
  • TimeZone Convert GMT to/from local zone
  • DateFormat Convert UDate to/from text

15
Date and Time Components
  • Fit together in a specific nested pattern

16
Date and Time Components
  • Fit together in a specific nested pattern
  • Create
  • TimeZone object zone
  • Calendar object cal
  • DateFormat object fmt
  • Set cals time zone to zone
  • Set fmts calendar to cal

17
Date and Time Components
  • If components are not nested explicitly, then
    they use default objects, which can lead to
    errors
  • DateFormat uses a default Calendar
  • Calendar uses a default TimeZone

18
Calendar Two Roles
  • Always set to a specific UDate
  • Converts UDate to/from fields
  • Fields are integer values for the month, day,
    year, hour, minutes, day of week, etc.
  • See calendar.h for complete field list

19
Detail Calendar Fields
  • Conversion of fields to UDatecal.clear()cal.se
    t(YEAR, 1999)cal.set(MONTH, JUNE)cal.set(DAY_O
    F_WEEK, MONDAY)cal.set(WEEK_OF_MONTH, 2)UDate
    d cal.getTime()

20
Detail Calendar Fields
  • Conversion of UDate to fields cal.setTime(myUDat
    e)int32_t month cal.get(MONTH)

21
Time Zones
  • Standard Olson (UNIX) time zone data
  • Over 400 international time zones
  • Does not rely on host OS
  • No historical time zone support
  • Time zones always used with calendars

22
Formatters Code Patterns
  • Code contains generic pattern engine
  • Locale resources contain different patterns
  • Different groups of patterns for different
    locales
  • Within each group, different patterns for
    different variants e.g., one for Wed 6 Sep 00
    and another for Wednesday 7 September 2000

23
Formatter Types
  • DateFormat already discussed
  • NumberFormat handles 1,234.56
  • MessageFormat handles 3 Files Found
  • ChoiceFormat handles no files/one file

24
Formatters Pattern Syntax
  • Each formatter supports its own pattern syntax
  • For number and date formats, most users can use
    locale data
  • For message format, users will have to write
    their own patterns
  • See headers for pattern syntax documentation

25
Future Directions
  • Support for time zone aliasing
  • Support for traditional calendar systems
  • Support for rule-based number formatting (e.g.,
    three hundred and sixty-four)

26
Exercises
  • Exercise 1 datefmt
  • Use DateFormat to format a date and time into
    several localized strings
  • Convert the date and time into local time zones

27
Exercises
  • Exercise 2 msgfmt
  • Use MessageFormat to format a number and date
  • Use a ChoiceFormat pattern to format the number
    idiomatically
Write a Comment
User Comments (0)
About PowerShow.com