| OLD | NEW |
| 1 part of dart.core; | 1 part of dart.core; |
| 2 class DateTime implements Comparable {static const int MONDAY = 1; | 2 class DateTime implements Comparable {static const int MONDAY = 1; |
| 3 static const int TUESDAY = 2; | 3 static const int TUESDAY = 2; |
| 4 static const int WEDNESDAY = 3; | 4 static const int WEDNESDAY = 3; |
| 5 static const int THURSDAY = 4; | 5 static const int THURSDAY = 4; |
| 6 static const int FRIDAY = 5; | 6 static const int FRIDAY = 5; |
| 7 static const int SATURDAY = 6; | 7 static const int SATURDAY = 6; |
| 8 static const int SUNDAY = 7; | 8 static const int SUNDAY = 7; |
| 9 static const int DAYS_PER_WEEK = 7; | 9 static const int DAYS_PER_WEEK = 7; |
| 10 static const int JANUARY = 1; | 10 static const int JANUARY = 1; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 return this; | 102 return this; |
| 103 } | 103 } |
| 104 DateTime toUtc() { | 104 DateTime toUtc() { |
| 105 if (isUtc) return this; | 105 if (isUtc) return this; |
| 106 return new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, isUtc:
true); | 106 return new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, isUtc:
true); |
| 107 } | 107 } |
| 108 static String _fourDigits(int n) { | 108 static String _fourDigits(int n) { |
| 109 int absN = n.abs(); | 109 int absN = n.abs(); |
| 110 String sign = n < 0 ? "-" : ""; | 110 String sign = n < 0 ? "-" : ""; |
| 111 if (absN >= 1000) return "$n"; | 111 if (absN >= 1000) return "$n"; |
| 112 if (absN >= 100) return "${sign} | 112 if (absN >= 100) return "${sign}0$absN"; |
| 113 0$absN"; | 113 if (absN >= 10) return "${sign}00$absN"; |
| 114 if (absN >= 10) return "${sign} | 114 return "${sign}000$absN"; |
| 115 00$absN"; | 115 } |
| 116 return "${sign} | |
| 117 000$absN"; | |
| 118 } | |
| 119 static String _sixDigits(int n) { | 116 static String _sixDigits(int n) { |
| 120 assert (n < -9999 || n > 9999); int absN = n.abs(); | 117 assert (n < -9999 || n > 9999); int absN = n.abs(); |
| 121 String sign = n < 0 ? "-" : "+"; | 118 String sign = n < 0 ? "-" : "+"; |
| 122 if (absN >= 100000) return "$sign$absN"; | 119 if (absN >= 100000) return "$sign$absN"; |
| 123 return "${sign} | 120 return "${sign}0$absN"; |
| 124 0$absN"; | 121 } |
| 125 } | |
| 126 static String _threeDigits(int n) { | 122 static String _threeDigits(int n) { |
| 127 if (n >= 100) return "${n} | 123 if (n >= 100) return "${n}"; |
| 128 "; | 124 if (n >= 10) return "0${n}"; |
| 129 if (n >= 10) return "0${n} | 125 return "00${n}"; |
| 130 "; | 126 } |
| 131 return "00${n} | |
| 132 "; | |
| 133 } | |
| 134 static String _twoDigits(int n) { | 127 static String _twoDigits(int n) { |
| 135 if (n >= 10) return "${n} | 128 if (n >= 10) return "${n}"; |
| 136 "; | 129 return "0${n}"; |
| 137 return "0${n} | 130 } |
| 138 "; | |
| 139 } | |
| 140 String toString() { | 131 String toString() { |
| 141 String y = _fourDigits(year); | 132 String y = _fourDigits(year); |
| 142 String m = _twoDigits(month); | 133 String m = _twoDigits(month); |
| 143 String d = _twoDigits(day); | 134 String d = _twoDigits(day); |
| 144 String h = _twoDigits(hour); | 135 String h = _twoDigits(hour); |
| 145 String min = _twoDigits(minute); | 136 String min = _twoDigits(minute); |
| 146 String sec = _twoDigits(second); | 137 String sec = _twoDigits(second); |
| 147 String ms = _threeDigits(millisecond); | 138 String ms = _threeDigits(millisecond); |
| 148 if (isUtc) { | 139 if (isUtc) { |
| 149 return "$y-$m-$d $h:$min:$sec.${ms} | 140 return "$y-$m-$d $h:$min:$sec.${ms}Z"; |
| 150 Z"; | 141 } |
| 151 } | 142 else { |
| 152 else { | 143 return "$y-$m-$d $h:$min:$sec.$ms"; |
| 153 return "$y-$m-$d $h:$min:$sec.$ms"; | 144 } |
| 154 } | 145 } |
| 155 } | |
| 156 String toIso8601String() { | 146 String toIso8601String() { |
| 157 String y = (year >= -9999 && year <= 9999) ? _fourDigits(year) : _sixDigits(year
); | 147 String y = (year >= -9999 && year <= 9999) ? _fourDigits(year) : _sixDigits(ye
ar); |
| 158 String m = _twoDigits(month); | 148 String m = _twoDigits(month); |
| 159 String d = _twoDigits(day); | 149 String d = _twoDigits(day); |
| 160 String h = _twoDigits(hour); | 150 String h = _twoDigits(hour); |
| 161 String min = _twoDigits(minute); | 151 String min = _twoDigits(minute); |
| 162 String sec = _twoDigits(second); | 152 String sec = _twoDigits(second); |
| 163 String ms = _threeDigits(millisecond); | 153 String ms = _threeDigits(millisecond); |
| 164 if (isUtc) { | 154 if (isUtc) { |
| 165 return "$y-$m-${d} | 155 return "$y-$m-${d}T$h:$min:$sec.${ms}Z"; |
| 166 T$h:$min:$sec.${ms} | 156 } |
| 167 Z"; | 157 else { |
| 168 } | 158 return "$y-$m-${d}T$h:$min:$sec.$ms"; |
| 169 else { | 159 } |
| 170 return "$y-$m-${d} | 160 } |
| 171 T$h:$min:$sec.$ms"; | |
| 172 } | |
| 173 } | |
| 174 DateTime add(Duration duration) { | 161 DateTime add(Duration duration) { |
| 175 int ms = millisecondsSinceEpoch; | 162 int ms = millisecondsSinceEpoch; |
| 176 return new DateTime.fromMillisecondsSinceEpoch(ms + duration.inMilliseconds, is
Utc: isUtc); | 163 return new DateTime.fromMillisecondsSinceEpoch(ms + duration.inMilliseconds,
isUtc: isUtc); |
| 177 } | 164 } |
| 178 DateTime subtract(Duration duration) { | 165 DateTime subtract(Duration duration) { |
| 179 int ms = millisecondsSinceEpoch; | 166 int ms = millisecondsSinceEpoch; |
| 180 return new DateTime.fromMillisecondsSinceEpoch(ms - duration.inMilliseconds, is
Utc: isUtc); | 167 return new DateTime.fromMillisecondsSinceEpoch(ms - duration.inMilliseconds,
isUtc: isUtc); |
| 181 } | 168 } |
| 182 Duration difference(DateTime other) { | 169 Duration difference(DateTime other) { |
| 183 int ms = millisecondsSinceEpoch; | 170 int ms = millisecondsSinceEpoch; |
| 184 int otherMs = other.millisecondsSinceEpoch; | 171 int otherMs = other.millisecondsSinceEpoch; |
| 185 return new Duration(milliseconds: ms - otherMs); | 172 return new Duration(milliseconds: ms - otherMs); |
| 186 } | 173 } |
| 187 external DateTime._internal(int year, int month, int day, int hour, int minute,
int second, int millisecond, bool isUtc); | 174 external DateTime._internal(int year, int month, int day, int hour, int minute,
int second, int millisecond, bool isUtc); |
| 188 external DateTime._now(); | 175 external DateTime._now(); |
| 189 external static int _brokenDownDateToMillisecondsSinceEpoch(int year, int month
, int day, int hour, int minute, int second, int millisecond, bool isUtc); | 176 external static int _brokenDownDateToMillisecondsSinceEpoch(int year, int month
, int day, int hour, int minute, int second, int millisecond, bool isUtc); |
| 190 external String get timeZoneName; | 177 external String get timeZoneName; |
| 191 external Duration get timeZoneOffset; | 178 external Duration get timeZoneOffset; |
| 192 external int get year; | 179 external int get year; |
| 193 external int get month; | 180 external int get month; |
| 194 external int get day; | 181 external int get day; |
| 195 external int get hour; | 182 external int get hour; |
| 196 external int get minute; | 183 external int get minute; |
| 197 external int get second; | 184 external int get second; |
| 198 external int get millisecond; | 185 external int get millisecond; |
| 199 external int get weekday; | 186 external int get weekday; |
| 200 } | 187 } |
| OLD | NEW |