-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from cquiroz/number-format
Date and Number Format basic implementation
- Loading branch information
Showing
13 changed files
with
1,197 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package java.text | ||
|
||
import java.util.Locale | ||
|
||
import locales.LocaleRegistry | ||
import locales.cldr.{CalendarPatterns, LDML} | ||
|
||
abstract class DateFormat protected () extends Format { | ||
// override final def format(obj: AnyRef, toAppendTo: StringBuffer, pos: FieldPosition): StringBuffer = ??? | ||
// def format(date: Date, toAppendTo: StringBuffer, pos: FieldPosition): StringBuffer = ??? | ||
|
||
// TODO implement | ||
// final def format(date: Date): String = ??? | ||
// def parse(source: String, parsePosition: ParsePosition): Date = ??? | ||
// def parse(source: String): Date = ??? | ||
// override final def parseObject(source: String, pos: ParsePosition): AnyRef = ??? | ||
// def setCalendar(newCalendar: Calendar): Unit = ??? | ||
// def getCalendar(): Calendar = ??? | ||
// def setNumberFormat(newNumberFormat: NumberFormat): Unit = ??? | ||
// def getNumberFormat(): NumberFormat = ??? | ||
// def setTimeZone(zone: TimeZone): Unit = ??? | ||
// def getTimeZone(): TimeZone = ??? | ||
// def setLenient(lenient: Boolean): Unit = ??? | ||
// def isLenient(): Boolean = ??? | ||
// override def hashCode(): Int = ??? | ||
// override def equals(obj: Any): Boolean = ??? | ||
// override def clone(): Any = ??? | ||
} | ||
|
||
object DateFormat { | ||
val ERA_FIELD: Int = 0 | ||
val YEAR_FIELD: Int = 1 | ||
val MONTH_FIELD: Int = 2 | ||
val DATE_FIELD: Int = 3 | ||
val HOUR_OF_DAY1_FIELD: Int = 4 | ||
val HOUR_OF_DAY0_FIELD: Int = 5 | ||
val MINUTE_FIELD: Int = 6 | ||
val SECOND_FIELD: Int = 7 | ||
val MILLISECOND_FIELD: Int = 8 | ||
val DAY_OF_WEEK_FIELD: Int = 9 | ||
val DAY_OF_YEAR_FIELD: Int = 10 | ||
val DAY_OF_WEEK_IN_MONTH_FIELD: Int = 11 | ||
val WEEK_OF_YEAR_FIELD: Int = 12 | ||
val WEEK_OF_MONTH_FIELD: Int = 13 | ||
val AM_PM_FIELD: Int = 14 | ||
val HOUR1_FIELD: Int = 15 | ||
val HOUR0_FIELD: Int = 16 | ||
val TIMEZONE_FIELD: Int = 17 | ||
|
||
val FULL: Int = 0 | ||
val LONG: Int = 1 | ||
val MEDIUM: Int = 2 | ||
val SHORT: Int = 3 | ||
val DEFAULT: Int = 2 | ||
|
||
private def parentPatterns(ldml: LDML): Option[CalendarPatterns] = | ||
ldml.calendarPatterns.orElse(ldml.parent.flatMap(parentPatterns)) | ||
|
||
private def patternsR(ldml: LDML, get: CalendarPatterns => Option[String]): Option[String] = | ||
ldml.calendarPatterns.flatMap(get).orElse(ldml.parent.flatMap(patternsR(_, get))) | ||
|
||
final def getTimeInstance(): DateFormat = getTimeInstance(DEFAULT) | ||
|
||
final def getTimeInstance(style: Int): DateFormat = | ||
getTimeInstance(style, Locale.getDefault(Locale.Category.FORMAT)) | ||
|
||
final def getTimeInstance(style: Int, aLocale: Locale): DateFormat = | ||
LocaleRegistry.ldml(aLocale).flatMap { ldml => | ||
val ptrn = patternsR(ldml, _.timePatterns.get(style)) | ||
ptrn.map(new SimpleDateFormat(_, aLocale)) | ||
}.getOrElse(new SimpleDateFormat("", aLocale)) | ||
|
||
final def getDateInstance(): DateFormat = getDateInstance(DEFAULT) | ||
|
||
final def getDateInstance(style: Int): DateFormat = | ||
getDateInstance(style, Locale.getDefault(Locale.Category.FORMAT)) | ||
|
||
final def getDateInstance(style: Int, aLocale: Locale): DateFormat = | ||
LocaleRegistry.ldml(aLocale).flatMap { ldml => | ||
val ptrn = patternsR(ldml, _.datePatterns.get(style)) | ||
ptrn.map(new SimpleDateFormat(_, aLocale)) | ||
}.getOrElse(new SimpleDateFormat("", aLocale)) | ||
|
||
final def getDateTimeInstance(): DateFormat = getDateInstance(DEFAULT) | ||
|
||
final def getDateTimeInstance(dateStyle: Int, timeStyle: Int): DateFormat = | ||
getDateTimeInstance(dateStyle, timeStyle, Locale.getDefault(Locale.Category.FORMAT)) | ||
|
||
final def getDateTimeInstance(dateStyle: Int, timeStyle: Int, aLocale: Locale): DateFormat = | ||
LocaleRegistry.ldml(aLocale).flatMap { ldml => | ||
val datePtrn = patternsR(ldml, _.datePatterns.get(dateStyle)) | ||
val timePtrn = patternsR(ldml, _.timePatterns.get(timeStyle)) | ||
(datePtrn, timePtrn) match { | ||
case (Some(d), Some(t)) => Some(new SimpleDateFormat(s"$d $t", aLocale)) | ||
case (Some(d), None) => Some(new SimpleDateFormat(s"$d", aLocale)) | ||
case (None, Some(t)) => Some(new SimpleDateFormat(s"$t", aLocale)) | ||
case _ => Some(new SimpleDateFormat("", aLocale)) | ||
} | ||
}.getOrElse(new SimpleDateFormat("", aLocale)) | ||
|
||
final def getInstance(): DateFormat = | ||
getDateTimeInstance(SHORT, SHORT) | ||
|
||
def getAvailableLocales(): Array[Locale] = Locale.getAvailableLocales | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package java.text | ||
|
||
class DecimalFormat(private[this] val pattern: String, private[this] var symbols: DecimalFormatSymbols) extends Format { | ||
def this(pattern: String) = this(pattern, DecimalFormatSymbols.getInstance()) | ||
|
||
//def this() = this("???", DecimalFormatSymbols.getInstance()) | ||
|
||
override final def format(obj: AnyRef, toAppendTo: StringBuffer, pos: FieldPosition): StringBuffer = ??? | ||
|
||
override final def parseObject(source: String, pos: ParsePosition): AnyRef = ??? | ||
|
||
// TODO implement | ||
//def format(number: Double, toAppendTo: StringBuffer, pos: FieldPosition): StringBuffer = ??? | ||
//def format(number: Long, toAppendTo: StringBuffer, pos: FieldPosition): StringBuffer = ??? | ||
//def parse(source: String, parsePosition: ParsePosition): Number = ??? | ||
//def parse(source: String): Number = ??? | ||
def getDecimalFormatSymbols(): DecimalFormatSymbols = symbols | ||
|
||
def setDecimalFormatSymbols(symbols: DecimalFormatSymbols): Unit = | ||
this.symbols = symbols | ||
|
||
// def getPositivePrefix(): String = ??? | ||
// def setPositivePrefix(newValue: String): Unit = ??? | ||
// def getNegativePrefix(): String = ??? | ||
// def setNegativePrefix(newValue: String): Unit = ??? | ||
// def getPositiveSuffix(): String = ??? | ||
// def setPositiveSuffix(newValue: String): Unit = ??? | ||
// def getNegativeSuffix(): String = ??? | ||
// def setNegativeSuffix(newValue: String): Unit = ??? | ||
// def getMultiplier(): Int = ??? | ||
// def setMultiplier(newValue: Int): Unit = ??? | ||
// override def setGroupingUsed(newValue: Boolean): Unit = ??? | ||
// def getGroupingSize(): Int = ??? | ||
// def setGroupingSize(newValue: Int): Unit = ??? | ||
// def isDecimalSeparatorAlwaysShown(): Boolean = ??? | ||
// def setDecimalSeparatorAlwaysShown(newValue: Boolean): Unit = ??? | ||
// def isParseBigDecimal(): Boolean = ??? | ||
// def setParseBigDecimal(newValue: Boolean): Unit = ??? | ||
// override def clone(): Any = ??? | ||
// override def hashCode(): Int = ??? | ||
// override def equals(obj: Any): Boolean = ??? | ||
def toPattern(): String = pattern | ||
// def toLocalizedPattern(): String = pattern | ||
// def applyPattern(pattern: String): Unit = ??? | ||
// def setMaximumIntegerDigits(newValue: Int): Unit = ??? | ||
// def setMinimumIntegerDigits(newValue: Int): Unit = ??? | ||
// def setMaximumFractionDigits(newValue: Int): Unit = ??? | ||
// def setMinimumFractionDigits(newValue: Int): Unit = ??? | ||
// def getMaximumIntegerDigits(): Int = ??? | ||
// def getMinimumIntegerDigits(): Int = ??? | ||
// def getMaximumFractionDigits(): Int = ??? | ||
// def getMinimumFractionDigits(): Int = ??? | ||
// def getCurrency(): Currency = ??? | ||
// def setCurrency(currency: Currency): Unit = ??? | ||
// def getRoundingMode(): RoundingMode = ??? | ||
// def setRoundingMode(currency: RoundingMode): Unit = ??? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package java.text | ||
|
||
import java.util.Locale | ||
|
||
abstract class NumberFormat protected () extends Format { | ||
override final def parseObject(source: String, pos: ParsePosition): AnyRef = ??? | ||
|
||
override def format(obj: AnyRef, toAppendTo: StringBuffer, pos: FieldPosition): StringBuffer = ??? | ||
|
||
// TODO implement | ||
// final def format(number: Double): String = ??? | ||
// final def format(number: Long): String = ??? | ||
// def format(number: Double, toAppendTo: StringBuffer, pos: FieldPosition): StringBuffer = ??? | ||
// def format(number: Long, toAppendTo: StringBuffer, pos: FieldPosition): StringBuffer = ??? | ||
// def parse(source: String, parsePosition: ParsePosition): Number = ??? | ||
// def parse(source: String): Number = ??? | ||
// def isParseIntegerOnly(): Boolean = ??? | ||
// def setParseIntegerOnly(value: Boolean): Unit = ??? | ||
// override def hashCode(): Int = ??? | ||
// override def equals(obj: Any): Boolean = ??? | ||
// override def clone(): Any = ??? | ||
// def isGroupingUsed(): Boolean = ??? | ||
// def setGroupingUsed(newValue: Boolean): Unit = ??? | ||
// def getMaximumIntegerDigits(): Int = ??? | ||
// def setMaximumIntegerDigits(newValue: Int): Unit = ??? | ||
// def getMinimumIntegerDigits(): Int = ??? | ||
// def setMinimumIntegerDigits(newValue: Int): Unit = ??? | ||
// def getMaximumFractionDigits(): Int = ??? | ||
// def setMaximumFractionDigits(newValue: Int): Unit = ??? | ||
// def getMinimumFractionDigits(): Int = ??? | ||
// def setMinimumFractionDigits(newValue: Int): Unit = ??? | ||
// def getCurrency(): Currency = ??? | ||
// def setCurrency(currency: Currency): Unit = ??? | ||
// def getRoundingMode(): RoundingMode = ??? | ||
// def setRoundingMode(currency: RoundingMode): Unit = ??? | ||
} | ||
|
||
object NumberFormat { | ||
val INTEGER_FIELD: Int = 0 | ||
val FRACTION_FIELD: Int = 1 | ||
|
||
//final def getInstance(): NumberFormat = ??? | ||
//def getInstance(inLocale: Locale): NumberFormat = ??? | ||
//final def getNumberInstance(): NumberFormat = ??? | ||
//def getNumberInstance(inLocale: Locale): NumberFormat = ??? | ||
//final def getIntegerInstance(): NumberFormat = ??? | ||
//def getIntegerInstance(inLocale: Locale): NumberFormat = ??? | ||
//final def getCurrencyInstance(): NumberFormat = ??? | ||
//def getCurrencyInstance(inLocale: Locale): NumberFormat = ??? | ||
//final def getPercentInstance(): NumberFormat = ??? | ||
//def getPercentInstance(inLocale: Locale): NumberFormat = ??? | ||
//def getAvailableLocales(): Array[Locale] = ??? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package java.text | ||
|
||
import java.util.Locale | ||
|
||
class SimpleDateFormat(private[this] val pattern: String, | ||
private[this] var symbols: DateFormatSymbols) extends DateFormat { | ||
def this(pattern: String) = this(pattern, DateFormatSymbols.getInstance()) | ||
|
||
def this(pattern: String, aLocale: Locale) = this(pattern, DateFormatSymbols.getInstance(aLocale)) | ||
|
||
//def this() = this("???", DecimalFormatSymbols.getInstance()) | ||
|
||
override final def format(obj: AnyRef, toAppendTo: StringBuffer, pos: FieldPosition): StringBuffer = ??? | ||
|
||
override final def parseObject(source: String, pos: ParsePosition): AnyRef = ??? | ||
|
||
// def set2DigitYearStart(startDate: Date): Unit = ??? | ||
// def get2DigitYearStart(): Date = ??? | ||
// override final def format(date: Date, toAppendTo: StringBuffer, pos: FieldPosition): StringBuffer = ??? | ||
// def formatToCharacterIterator(obj: AnyRef): AttributedCharacterIterator = | ||
// def parse(text: String, pos: ParsePosition): Date = ??? | ||
def toPattern(): String = pattern | ||
// def toLocalizedPattern(): String = pattern | ||
// def applyPattern(pattern: String): Unit = ??? | ||
// def applyLocalizedPattern(pattern: String): Unit = ??? | ||
def getDateFormatSymbols(): DateFormatSymbols = symbols | ||
|
||
def setDateFormatSymbols(symbols: DateFormatSymbols): Unit = | ||
this.symbols = symbols | ||
|
||
// override def clone(): Any = ??? | ||
// override def hashCode(): Int = ??? | ||
// override def equals(obj: Any): Boolean = ??? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.