<commit_before>/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.core.format;

import java.text.ParseException;
import com.ibm.icu.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import com.ibm.icu.util.ULocale;
import com.ibm.icu.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * DateFormatter.
 * 
 * Design for Class DateFormatter.This version is for open source, so we only
 * apply the function which Java has provided. Beside these basic function, in
 * this version, we also provide some new API for further implementation in the
 * future
 * 
 * @version $Revision: 1.9 $ $Date: 2006/02/22 06:44:15 $
 */
public class DateFormatter
{

	/**
	 * Comment for <code>formatPattern</code> record the string pattern
	 */
	private String formatPattern;

	/**
	 * Comment for <code>dateFormat</code> used for two methods,
	 * createDateFormat() and format()
	 */
	private com.ibm.icu.text.DateFormat dateFormat;

	/**
	 * Comment for <code>locale</code> used for record Locale information
	 */
	private ULocale locale = ULocale.getDefault( );

	/**
	 * logger used to log syntax errors.
	 */
	static protected Logger logger = Logger.getLogger( DateFormatter.class
			.getName( ) );

	/**
	 * constuctor method with no paremeter
	 */
	public DateFormatter( )
	{
		applyPattern( null );
	}

	/**
	 * constuctor method with String parameter
	 * 
	 * @param pattern
	 */
	public DateFormatter( String pattern )
	{
		applyPattern( pattern );
	}

	/**
	 * constuctor method with Locale parameters
	 * 
	 * @param localeLoc
	 */
	public DateFormatter( ULocale localeLoc )
	{
		// Leave locale to default if none provided
		if ( localeLoc != null )
			locale = localeLoc;
		applyPattern( null );
	}

	/**
	 * @deprecated since 2.1
	 * @return
	 */
	public DateFormatter( Locale localeLoc )
	{
		this(ULocale.forLocale(localeLoc));
	}

	/**
	 * constuctor method with two parameters, one is String type while the other
	 * is Locale type
	 * 
	 * @param pattern
	 * @param localeLoc
	 */
	public DateFormatter( String pattern, ULocale localeLoc )
	{
		// Leave locale to default if none provided
		if ( localeLoc != null )
			locale = localeLoc;
		applyPattern( pattern );
	}

	/**
	 * @deprecated since 2.1
	 * @return
	 */
	public DateFormatter( String pattern, Locale localeLoc )
	{
		this(pattern, ULocale.forLocale(localeLoc));
	}
	
	

	/**
	 * get the string pattern
	 * 
	 * @return
	 */
	public String getPattern( )
	{
		return this.formatPattern;
	}

	/**
	 * define pattern and locale here
	 * 
	 * @param formatString
	 */
	public void applyPattern( String formatString )
	{
		try
		{
			this.formatPattern = formatString;

			/*
			 * we can seperate these single name-based patterns form those
			 * patterns with multinumber letters
			 */
			if ( formatString == null || "Unformatted".equals(formatString)) //$NON-NLS-1$
			{
				formatPattern = "";
				dateFormat = com.ibm.icu.text.DateFormat.getDateTimeInstance(
						com.ibm.icu.text.DateFormat.MEDIUM, com.ibm.icu.text.DateFormat.SHORT,
						locale );
				return;

			}
			if ( formatString.length( ) == 1 )
			{
				char patternTemp = formatString.charAt( 0 );
				switch ( patternTemp )
				{
					case 'G' :
						dateFormat = com.ibm.icu.text.DateFormat.getDateTimeInstance(
								com.ibm.icu.text.DateFormat.LONG,
								com.ibm.icu.text.DateFormat.LONG, locale );
						return;
					case 'D' :

						dateFormat = com.ibm.icu.text.DateFormat.getDateInstance(
								com.ibm.icu.text.DateFormat.LONG, locale );
						return;
					case 'd' :

						dateFormat = com.ibm.icu.text.DateFormat.getDateInstance(
								com.ibm.icu.text.DateFormat.SHORT, locale );
						return;
					case 'T' :

						dateFormat = com.ibm.icu.text.DateFormat.getTimeInstance(
								com.ibm.icu.text.DateFormat.LONG, locale );
						return;
					case 't' :
						dateFormat = new SimpleDateFormat( "HH:mm", locale );
						return;
					case 'f' :

						dateFormat = com.ibm.icu.text.DateFormat.getDateTimeInstance(
								com.ibm.icu.text.DateFormat.LONG,
								com.ibm.icu.text.DateFormat.SHORT, locale );
						return;
					case 'F' :
						dateFormat = com.ibm.icu.text.DateFormat.getDateTimeInstance(
								com.ibm.icu.text.DateFormat.LONG,
								com.ibm.icu.text.DateFormat.LONG, locale );
						return;
					case 'g' :

						dateFormat = com.ibm.icu.text.DateFormat.getDateTimeInstance(
								com.ibm.icu.text.DateFormat.SHORT,
								com.ibm.icu.text.DateFormat.SHORT, locale );
						return;
					case 'M' :
					case 'm' :
						dateFormat = new SimpleDateFormat( "MM/dd", locale );<commit_msg>Added two formatter codes<commit_after>/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.core.format;

import java.text.ParseException;
import com.ibm.icu.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import com.ibm.icu.util.ULocale;
import com.ibm.icu.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * DateFormatter.
 * 
 * Design for Class DateFormatter.This version is for open source, so we only
 * apply the function which Java has provided. Beside these basic function, in
 * this version, we also provide some new API for further implementation in the
 * future
 * 
 * @version $Revision: 1.10 $ $Date: 2006/07/12 22:43:42 $
 */
public class DateFormatter
{

	/**
	 * Comment for <code>formatPattern</code> record the string pattern
	 */
	private String formatPattern;

	/**
	 * Comment for <code>dateFormat</code> used for two methods,
	 * createDateFormat() and format()
	 */
	private com.ibm.icu.text.DateFormat dateFormat;

	/**
	 * Comment for <code>locale</code> used for record Locale information
	 */
	private ULocale locale = ULocale.getDefault( );

	/**
	 * logger used to log syntax errors.
	 */
	static protected Logger logger = Logger.getLogger( DateFormatter.class
			.getName( ) );

	/**
	 * constuctor method with no paremeter
	 */
	public DateFormatter( )
	{
		applyPattern( null );
	}

	/**
	 * constuctor method with String parameter
	 * 
	 * @param pattern
	 */
	public DateFormatter( String pattern )
	{
		applyPattern( pattern );
	}

	/**
	 * constuctor method with Locale parameters
	 * 
	 * @param localeLoc
	 */
	public DateFormatter( ULocale localeLoc )
	{
		// Leave locale to default if none provided
		if ( localeLoc != null )
			locale = localeLoc;
		applyPattern( null );
	}

	/**
	 * @deprecated since 2.1
	 * @return
	 */
	public DateFormatter( Locale localeLoc )
	{
		this(ULocale.forLocale(localeLoc));
	}

	/**
	 * constuctor method with two parameters, one is String type while the other
	 * is Locale type
	 * 
	 * @param pattern
	 * @param localeLoc
	 */
	public DateFormatter( String pattern, ULocale localeLoc )
	{
		// Leave locale to default if none provided
		if ( localeLoc != null )
			locale = localeLoc;
		applyPattern( pattern );
	}

	/**
	 * @deprecated since 2.1
	 * @return
	 */
	public DateFormatter( String pattern, Locale localeLoc )
	{
		this(pattern, ULocale.forLocale(localeLoc));
	}
	
	

	/**
	 * get the string pattern
	 * 
	 * @return
	 */
	public String getPattern( )
	{
		return this.formatPattern;
	}

	/**
	 * define pattern and locale here
	 * 
	 * @param formatString
	 */
	public void applyPattern( String formatString )
	{
		try
		{
			this.formatPattern = formatString;

			/*
			 * we can seperate these single name-based patterns form those
			 * patterns with multinumber letters
			 */
			if ( formatString == null || "Unformatted".equals(formatString)) //$NON-NLS-1$
			{
				formatPattern = "";
				dateFormat = com.ibm.icu.text.DateFormat.getDateTimeInstance(
						com.ibm.icu.text.DateFormat.MEDIUM, com.ibm.icu.text.DateFormat.SHORT,
						locale );
				return;

			}
			if ( formatString.length( ) == 1 )
			{
				char patternTemp = formatString.charAt( 0 );
				switch ( patternTemp )
				{
					case 'G' :
						dateFormat = com.ibm.icu.text.DateFormat.getDateTimeInstance(
								com.ibm.icu.text.DateFormat.LONG,
								com.ibm.icu.text.DateFormat.LONG, locale );
						return;
					case 'D' :

						dateFormat = com.ibm.icu.text.DateFormat.getDateInstance(
								com.ibm.icu.text.DateFormat.LONG, locale );
						return;
					case 'd' :

						dateFormat = com.ibm.icu.text.DateFormat.getDateInstance(
								com.ibm.icu.text.DateFormat.SHORT, locale );
						return;
					case 'T' :

						dateFormat = com.ibm.icu.text.DateFormat.getTimeInstance(
								com.ibm.icu.text.DateFormat.LONG, locale );
						return;
					case 't' :
						dateFormat = new SimpleDateFormat( "HH:mm", locale );
						return;
					case 'f' :
						dateFormat = com.ibm.icu.text.DateFormat.getDateTimeInstance(
								com.ibm.icu.text.DateFormat.LONG,
								com.ibm.icu.text.DateFormat.SHORT, locale );
						return;
					case 'F' :
						dateFormat = com.ibm.icu.text.DateFormat.getDateTimeInstance(
								com.ibm.icu.text.DateFormat.LONG,
								com.ibm.icu.text.DateFormat.LONG, locale );
						return;
                    case 'i' :
                        dateFormat = com.ibm.icu.text.DateFormat.getDateTimeInstance(
                                                com.ibm.icu.text.DateFormat.SHORT,
                                                com.ibm.icu.text.DateFormat.MEDIUM, locale );
                        return;
                        
                    case 'I' :
                        dateFormat = com.ibm.icu.text.DateFormat.getDateTimeInstance(
                                                com.ibm.icu.text.DateFormat.SHORT,
                                                com.ibm.icu.text.DateFormat.LONG, locale );
                        return;
					case 'g' :

						dateFormat = com.ibm.icu.text.DateFormat.getDateTimeInstance(
								com.ibm.icu.text.DateFormat.SHORT,
								com.ibm.icu.text.DateFormat.SHORT, locale );
						return;
					case 'M' :
					case 'm' :
						dateFormat = new SimpleDateFormat( "MM/dd", locale );
{'fraction_non_alphanumeric': 0.13770431924025203, 'fraction_numerical': 0.005752899278604694, 'mean_word_length': 2.6727028839704894, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3838246', 'n_tokens_mistral': 4017, 'n_tokens_neox': 3271, 'n_words': 805}