Skip to content

Commit

Permalink
Change Intl's internal padTo method to use padLeft
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=111562075
  • Loading branch information
alan-knight committed Jan 7, 2016
1 parent c2b7d3d commit 35dbead
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions lib/src/intl/date_format_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ class _DateFormatPatternField extends _DateFormatField {
return symbols.QUARTERS[quarter];
}
}

String formatDayOfMonth(DateTime date) {
return padTo(width, date.day);
}
Expand Down Expand Up @@ -612,9 +613,8 @@ class _DateFormatPatternField extends _DateFormatField {

String formatDayOfWeek(DateTime date) {
// Note that Dart's weekday returns 1 for Monday and 7 for Sunday.
return (width >= 4
? symbols.WEEKDAYS
: symbols.SHORTWEEKDAYS)[(date.weekday) % 7];
return (width >= 4 ? symbols.WEEKDAYS : symbols.SHORTWEEKDAYS)[
(date.weekday) % 7];
}

void parseDayOfWeek(_Stream input) {
Expand Down Expand Up @@ -650,17 +650,9 @@ class _DateFormatPatternField extends _DateFormatField {
}

/**
* Return a string representation of the object padded to the left with
* zeros. Primarily useful for numbers.
*/
String padTo(int width, Object toBePrinted) {
var basicString = toBePrinted.toString();
if (basicString.length >= width) return basicString;
var buffer = new StringBuffer();
for (var i = 0; i < width - basicString.length; i++) {
buffer.write('0');
}
buffer.write(basicString);
return buffer.toString();
}
* Return a string representation of the object padded to the left with
* zeros. Primarily useful for numbers.
*/
static String padTo(int width, Object toBePrinted) =>
'$toBePrinted'.padLeft(width, '0');
}

0 comments on commit 35dbead

Please sign in to comment.