Skip to content

Commit

Permalink
Build failed in release mode on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Heromyth committed Jul 1, 2020
1 parent 83f6db5 commit 7a339c3
Showing 1 changed file with 44 additions and 45 deletions.
89 changes: 44 additions & 45 deletions source/hunt/time/format/LocalizedPrinterParser.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module hunt.time.format.LocalizedPrinterParser;
import hunt.time.chrono.Chronology;
import hunt.time.chrono.ChronoLocalDate;
import hunt.time.format.DateTimeFormatter;
import hunt.time.format.DateTimeFormatterBuilder;
import hunt.time.format.DateTimeParseContext;
import hunt.time.format.DateTimePrinterParser;
import hunt.time.format.DateTimePrintContext;
Expand All @@ -17,80 +18,79 @@ import hunt.collection.Map;
import hunt.Exceptions;
import hunt.util.Locale;

import std.concurrency : initOnce;

//-----------------------------------------------------------------------
/**
* Prints or parses a localized pattern.
*/
static final class LocalizedPrinterParser : DateTimePrinterParser
final class LocalizedPrinterParser : DateTimePrinterParser
{
/** Cache of formatters. */
// __gshared Map!(string, DateTimeFormatter) FORMATTER_CACHE;
static Map!(string, DateTimeFormatter) FORMATTER_CACHE() {
__gshared Map!(string, DateTimeFormatter) inst;
return initOnce!(inst)(
new HashMap!(string, DateTimeFormatter)(16, 0.75f /* , 2 */ ));
}

private FormatStyle dateStyle;
private FormatStyle timeStyle;

// shared static this()
// {
// FORMATTER_CACHE = new HashMap!(string, DateTimeFormatter)(16, 0.75f /* , 2 */ );
mixin(MakeGlobalVar!(Map!(string, DateTimeFormatter))("FORMATTER_CACHE",`new HashMap!(string, DateTimeFormatter)(16, 0.75f /* , 2 */ )`));
// }
/**
* Constructor.
*
* @param dateStyle the date style to use, may be null
* @param timeStyle the time style to use, may be null
*/
* Constructor.
*
* @param dateStyle the date style to use, may be null
* @param timeStyle the time style to use, may be null
*/
this(FormatStyle dateStyle, FormatStyle timeStyle)
{
// validated by caller
this.dateStyle = dateStyle;
this.timeStyle = timeStyle;
}

override public bool format(DateTimePrintContext context, StringBuilder buf)
override bool format(DateTimePrintContext context, StringBuilder buf)
{
Chronology chrono = Chronology.from(context.getTemporal());
return formatter(context.getLocale(), chrono).toPrinterParser(false)
.format(context, buf);
}

override public int parse(DateTimeParseContext context, string text, int position)
override int parse(DateTimeParseContext context, string text, int position)
{
Chronology chrono = context.getEffectiveChronology();
return formatter(context.getLocale(), chrono).toPrinterParser(false)
.parse(context, text, position);
}

/**
* Gets the formatter to use.
* !(p)
* The formatter will be the most appropriate to use for the date and time style _in the locale.
* For example, some locales will use the month name while others will use the number.
*
* @param locale the locale to use, not null
* @param chrono the chronology to use, not null
* @return the formatter, not null
* @throws IllegalArgumentException if the formatter cannot be found
*/
* Gets the formatter to use.
* !(p)
* The formatter will be the most appropriate to use for the date and time style _in the locale.
* For example, some locales will use the month name while others will use the number.
*
* @param locale the locale to use, not null
* @param chrono the chronology to use, not null
* @return the formatter, not null
* @throws IllegalArgumentException if the formatter cannot be found
*/
private DateTimeFormatter formatter(Locale locale, Chronology chrono)
{
// string key = chrono.getId() ~ '|' ~ locale.toString() ~ '|' ~ dateStyle.name() ~ timeStyle.name();
// DateTimeFormatter formatter = FORMATTER_CACHE.get(key);
// if (formatter is null)
// {
// string pattern = getLocalizedDateTimePattern(dateStyle,
// timeStyle, chrono, locale);
// formatter = new DateTimeFormatterBuilder().appendPattern(pattern)
// .toFormatter(locale);
// DateTimeFormatter old = FORMATTER_CACHE.putIfAbsent(key, formatter);
// if (old !is null)
// {
// formatter = old;
// }
// }
// return formatter;
implementationMissing(false);
return null;
string key = chrono.getId() ~ '|' ~ locale.toString() ~ '|' ~ dateStyle.name() ~ timeStyle.name();
DateTimeFormatter formatter = FORMATTER_CACHE.get(key);
if (formatter is null) {
string pattern = getLocalizedDateTimePattern(dateStyle,
timeStyle, chrono, locale);
formatter = new DateTimeFormatterBuilder().appendPattern(pattern)
.toFormatter(locale);
DateTimeFormatter old = FORMATTER_CACHE.putIfAbsent(key, formatter);
if (old !is null) {
formatter = old;
}
}
return formatter;
// implementationMissing(false);
// return null;
}


Expand All @@ -110,9 +110,8 @@ static final class LocalizedPrinterParser : DateTimePrinterParser
* @return the locale and Chronology specific formatting pattern
* @throws IllegalArgumentException if both dateStyle and timeStyle are null
*/
public static string getLocalizedDateTimePattern(FormatStyle dateStyle,
FormatStyle timeStyle, Chronology chrono, Locale locale)
{
static string getLocalizedDateTimePattern(FormatStyle dateStyle,
FormatStyle timeStyle, Chronology chrono, Locale locale) {
// assert(locale, "locale");
// assert(chrono, "chrono");
// if (dateStyle is null && timeStyle is null) {
Expand All @@ -128,7 +127,7 @@ static final class LocalizedPrinterParser : DateTimePrinterParser
return null;
}

override public string toString()
override string toString()
{
return "Localized(" ~ (dateStyle !is null ? dateStyle.name()
: "") ~ "," ~ (timeStyle !is null ? timeStyle.name() : "") ~ ")";
Expand Down

0 comments on commit 7a339c3

Please sign in to comment.