Skip to content

Commit

Permalink
Fix code style in DateTimeFormat
Browse files Browse the repository at this point in the history
***NO_CI***
  • Loading branch information
josesimoes authored Oct 8, 2021
1 parent 7eeb203 commit d81e62f
Showing 1 changed file with 148 additions and 148 deletions.
296 changes: 148 additions & 148 deletions nanoFramework.CoreLibrary/System/Globalization/DateTimeFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,64 +247,64 @@ private static String FormatCustomized(DateTime dateTime, String format, DateTim
switch (ch)
{
case ':':
tempResult = dtfi.TimeSeparator;
tokenLen = 1;
break;
tempResult = dtfi.TimeSeparator;
tokenLen = 1;
break;
case '/':
tempResult = dtfi.DateSeparator;
tokenLen = 1;
break;
tempResult = dtfi.DateSeparator;
tokenLen = 1;
break;
case '\'':
case '\"':
tempResult = ParseQuoteString(format, i, out tokenLen);
break;
tempResult = ParseQuoteString(format, i, out tokenLen);
break;
case '%':
// Optional format character.
// For example, format string "%d" will print day of month
// without leading zero. Most of the cases, "%" can be ignored.
nextChar = ParseNextChar(format, i);
// nextChar will be -1 if we already reach the end of the format string.
// Besides, we will not allow "%%" appear in the pattern.
if (nextChar >= 0 && nextChar != '%')
{
tempResult = FormatCustomized(dateTime, ((char)nextChar).ToString(), dtfi);
tokenLen = 2;
}
else
{
//
// This means that '%' is at the end of the format string or
// "%%" appears in the format string.
//
throw new ArgumentException("Format_InvalidString");
}
break;
// Optional format character.
// For example, format string "%d" will print day of month
// without leading zero. Most of the cases, "%" can be ignored.
nextChar = ParseNextChar(format, i);
// nextChar will be -1 if we already reach the end of the format string.
// Besides, we will not allow "%%" appear in the pattern.
if (nextChar >= 0 && nextChar != '%')
{
tempResult = FormatCustomized(dateTime, ((char)nextChar).ToString(), dtfi);
tokenLen = 2;
}
else
{
//
// This means that '%' is at the end of the format string or
// "%%" appears in the format string.
//
throw new ArgumentException("Format_InvalidString");
}
break;
case '\\':
// Escaped character. Can be used to insert character into the format string.
// For exmple, "\d" will insert the character 'd' into the string.
//
// NOTENOTE : we can remove this format character if we enforce the enforced quote
// character rule.
// That is, we ask everyone to use single quote or double quote to insert characters,
// then we can remove this character.
//
nextChar = ParseNextChar(format, i);
if (nextChar >= 0)
{
tempResult = ((char)nextChar).ToString();
tokenLen = 2;
}
else
{
// Escaped character. Can be used to insert character into the format string.
// For exmple, "\d" will insert the character 'd' into the string.
//
// This means that '\' is at the end of the formatting string.
// NOTENOTE : we can remove this format character if we enforce the enforced quote
// character rule.
// That is, we ask everyone to use single quote or double quote to insert characters,
// then we can remove this character.
//
throw new ArgumentException("Format_InvalidString");
}
break;
nextChar = ParseNextChar(format, i);
if (nextChar >= 0)
{
tempResult = ((char)nextChar).ToString();
tokenLen = 2;
}
else
{
//
// This means that '\' is at the end of the formatting string.
//
throw new ArgumentException("Format_InvalidString");
}
break;
default:
doneParsingCh = false;
break;
doneParsingCh = false;
break;
}

if (!doneParsingCh)
Expand All @@ -313,95 +313,95 @@ private static String FormatCustomized(DateTime dateTime, String format, DateTim
switch (ch)
{
case 'h':
var hour12 = dateTime.Hour % 12;
if (hour12 == 0) hour12 = 12;
tempResult = FormatDigits(hour12, tokenLen);
break;
var hour12 = dateTime.Hour % 12;
if (hour12 == 0) hour12 = 12;
tempResult = FormatDigits(hour12, tokenLen);
break;
case 'H':
tempResult = FormatDigits(dateTime.Hour, tokenLen);
break;
tempResult = FormatDigits(dateTime.Hour, tokenLen);
break;
case 'm':
tempResult = FormatDigits(dateTime.Minute, tokenLen);
break;
tempResult = FormatDigits(dateTime.Minute, tokenLen);
break;
case 's':
tempResult = FormatDigits(dateTime.Second, tokenLen);
break;
tempResult = FormatDigits(dateTime.Second, tokenLen);
break;
case 'f':
if (tokenLen <= _maxSecondsFractionDigits)
{
var precision = 3;
var fraction = dateTime.Millisecond;
if (tokenLen <= _maxSecondsFractionDigits)
{
var precision = 3;
var fraction = dateTime.Millisecond;

// Note: Need to add special case when tokenLen > precision to begin with
// if we're to change MaxSecondsFractionDigits to be more than 3
// Note: Need to add special case when tokenLen > precision to begin with
// if we're to change MaxSecondsFractionDigits to be more than 3

while (tokenLen < precision)
{
fraction /= 10;
precision--;
}
while (tokenLen < precision)
{
fraction /= 10;
precision--;
}

tempResult = FormatDigits(fraction, tokenLen);
}
else throw new ArgumentException("Format_InvalidString");
break;
tempResult = FormatDigits(fraction, tokenLen);
}
else throw new ArgumentException("Format_InvalidString");
break;
case 't':
if (tokenLen == 1)
{
if (dateTime.Hour < 12)
if (tokenLen == 1)
{
if (dtfi.AMDesignator.Length >= 1) tempResult = dtfi.AMDesignator[0].ToString();
if (dateTime.Hour < 12)
{
if (dtfi.AMDesignator.Length >= 1) tempResult = dtfi.AMDesignator[0].ToString();
}
else
{
if (dtfi.PMDesignator.Length >= 1) tempResult = dtfi.PMDesignator[0].ToString();
}

}
else tempResult = dateTime.Hour < 12 ? dtfi.AMDesignator : dtfi.PMDesignator;
break;
case 'd':
//
// tokenLen == 1 : Day of month as digits with no leading zero.
// tokenLen == 2 : Day of month as digits with leading zero for single-digit months.
// tokenLen == 3 : Day of week as a three-leter abbreviation.
// tokenLen >= 4 : Day of week as its full name.
//
if (tokenLen <= 2) tempResult = FormatDigits(dateTime.Day, tokenLen);
else
{
if (dtfi.PMDesignator.Length >= 1) tempResult = dtfi.PMDesignator[0].ToString();
}
var dayOfWeek = (int)dateTime.DayOfWeek;

}
else tempResult = dateTime.Hour < 12 ? dtfi.AMDesignator : dtfi.PMDesignator;
break;
case 'd':
//
// tokenLen == 1 : Day of month as digits with no leading zero.
// tokenLen == 2 : Day of month as digits with leading zero for single-digit months.
// tokenLen == 3 : Day of week as a three-leter abbreviation.
// tokenLen >= 4 : Day of week as its full name.
//
if (tokenLen <= 2) tempResult = FormatDigits(dateTime.Day, tokenLen);
else
{
var dayOfWeek = (int)dateTime.DayOfWeek;

tempResult = tokenLen == 3 ? dtfi.AbbreviatedDayNames[dayOfWeek] : dtfi.DayNames[dayOfWeek];
}
break;
tempResult = tokenLen == 3 ? dtfi.AbbreviatedDayNames[dayOfWeek] : dtfi.DayNames[dayOfWeek];
}
break;
case 'M':
//
// tokenLen == 1 : Month as digits with no leading zero.
// tokenLen == 2 : Month as digits with leading zero for single-digit months.
// tokenLen == 3 : Month as a three-letter abbreviation.
// tokenLen >= 4 : Month as its full name.
//
var month = dateTime.Month;
if (tokenLen <= 2) tempResult = FormatDigits(month, tokenLen);
else tempResult = tokenLen == 3 ? dtfi.AbbreviatedMonthNames[month - 1] : dtfi.MonthNames[month - 1];
break;
//
// tokenLen == 1 : Month as digits with no leading zero.
// tokenLen == 2 : Month as digits with leading zero for single-digit months.
// tokenLen == 3 : Month as a three-letter abbreviation.
// tokenLen >= 4 : Month as its full name.
//
var month = dateTime.Month;
if (tokenLen <= 2) tempResult = FormatDigits(month, tokenLen);
else tempResult = tokenLen == 3 ? dtfi.AbbreviatedMonthNames[month - 1] : dtfi.MonthNames[month - 1];
break;
case 'y':
// Notes about OS behavior:
// y: Always print (year % 100). No leading zero.
// yy: Always print (year % 100) with leading zero.
// yyy/yyyy/yyyyy/... : Print year value. With leading zeros.
// Notes about OS behavior:
// y: Always print (year % 100). No leading zero.
// yy: Always print (year % 100) with leading zero.
// yyy/yyyy/yyyyy/... : Print year value. With leading zeros.

var year = dateTime.Year;
var year = dateTime.Year;

tempResult = tokenLen <= 2 ? FormatDigits(year % 100, tokenLen) : year.ToString();
tempResult = tokenLen <= 2 ? FormatDigits(year % 100, tokenLen) : year.ToString();

if (tempResult.Length < tokenLen) tempResult = new string('0', tokenLen - tempResult.Length) + tempResult;
break;
if (tempResult.Length < tokenLen) tempResult = new string('0', tokenLen - tempResult.Length) + tempResult;
break;

default:
tempResult = tokenLen == 1 ? ch.ToString() : new String(ch, tokenLen);
break;
tempResult = tokenLen == 1 ? ch.ToString() : new String(ch, tokenLen);
break;
}
}

Expand All @@ -419,52 +419,52 @@ internal static String GetRealFormat(String format, DateTimeFormatInfo dtfi)
switch (format[0])
{
case 'd': // Short Date
realFormat = dtfi.ShortDatePattern;
break;
realFormat = dtfi.ShortDatePattern;
break;
case 'D': // Long Date
realFormat = dtfi.LongDatePattern;
break;
realFormat = dtfi.LongDatePattern;
break;
case 'f': // Full (long date + short time)
realFormat = dtfi.LongDatePattern + " " + dtfi.ShortTimePattern;
break;
realFormat = dtfi.LongDatePattern + " " + dtfi.ShortTimePattern;
break;
case 'F': // Full (long date + long time)
realFormat = dtfi.FullDateTimePattern;
break;
realFormat = dtfi.FullDateTimePattern;
break;
case 'g': // General (short date + short time)
realFormat = dtfi.GeneralShortTimePattern;
break;
realFormat = dtfi.GeneralShortTimePattern;
break;
case 'G': // General (short date + long time)
realFormat = dtfi.GeneralLongTimePattern;
break;
realFormat = dtfi.GeneralLongTimePattern;
break;
case 'm':
case 'M': // Month/Day Date
realFormat = dtfi.MonthDayPattern;
break;
realFormat = dtfi.MonthDayPattern;
break;
case 'r':
case 'R': // RFC 1123 Standard
realFormat = dtfi.RFC1123Pattern;
break;
realFormat = dtfi.RFC1123Pattern;
break;
case 's': // Sortable without Time Zone Info
realFormat = dtfi.SortableDateTimePattern;
break;
realFormat = dtfi.SortableDateTimePattern;
break;
case 't': // Short Time
realFormat = dtfi.ShortTimePattern;
break;
realFormat = dtfi.ShortTimePattern;
break;
case 'T': // Long Time
realFormat = dtfi.LongTimePattern;
break;
realFormat = dtfi.LongTimePattern;
break;
case 'u': // Universal with Sortable format
realFormat = dtfi.UniversalSortableDateTimePattern;
break;
realFormat = dtfi.UniversalSortableDateTimePattern;
break;
case 'U': // Universal with Full (long date + long time) format
realFormat = dtfi.FullDateTimePattern;
break;
realFormat = dtfi.FullDateTimePattern;
break;
case 'y':
case 'Y': // Year/Month Date
realFormat = dtfi.YearMonthPattern;
break;
realFormat = dtfi.YearMonthPattern;
break;
default:
throw new ArgumentException("Format_InvalidString");
throw new ArgumentException("Format_InvalidString");
}

return realFormat;
Expand Down

0 comments on commit d81e62f

Please sign in to comment.