Skip to content

Commit 6fc0f20

Browse files
authored
Use DateTime.utc() for sanity (#8783)
1 parent 1eb1135 commit 6fc0f20

File tree

6 files changed

+33
-33
lines changed

6 files changed

+33
-33
lines changed

app/lib/service/download_counts/download_counts.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class CountData {
7979
/// Process and store download counts given in [dayCounts] on the form
8080
/// {version: #downloads} for a date given by [dateTime].
8181
void addDownloadCounts(Map<String, int> dayCounts, DateTime dateTime) {
82-
final date = DateTime(dateTime.year, dateTime.month, dateTime.day);
82+
final date = DateTime.utc(dateTime.year, dateTime.month, dateTime.day);
8383
newestDate ??= date.addCalendarDays(-1);
8484

8585
final nextNewestDate = date.isAfter(newestDate!) ? date : newestDate!;

app/test/service/download_counts/computations_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void main() {
3030
'4.0.0-0': 2,
3131
'6.1.0': 2,
3232
};
33-
final date = DateTime.parse('1986-02-16');
33+
final date = DateTime.parse('1986-02-16T00:00:00Z');
3434
var downloadCounts1 = await downloadCountsBackend.updateDownloadCounts(
3535
pkg, versionsCounts, date);
3636
for (var i = 1; i < 5; i++) {
@@ -128,7 +128,7 @@ void main() {
128128
group('weekly download counts', () {
129129
testWithProfile('compute weekly', fn: () async {
130130
final pkg = 'foo';
131-
final date = DateTime.parse('1986-02-16');
131+
final date = DateTime.parse('1986-02-16T00:00:00Z');
132132
final versionsCounts = {
133133
'1.0.1': 2,
134134
'2.0.0-alpha': 2,
@@ -172,7 +172,7 @@ void main() {
172172

173173
testWithProfile('compute weekly for all verion ranges', fn: () async {
174174
final pkg = 'foo';
175-
final date = DateTime.parse('1986-02-16');
175+
final date = DateTime.parse('1986-02-16T00:00:00Z');
176176
final versions = [
177177
'1.1.0',
178178
'2.0.0-alpha',

app/test/service/download_counts/download_counts_major_test.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void main() {
4646
}
4747

4848
test('Add counts on following date', () async {
49-
final initialLastDate = DateTime.parse('1986-02-16');
49+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
5050
final countData = setupInitialCounts(initialLastDate);
5151

5252
// Extend existing counts and expel the lowest range.
@@ -84,7 +84,7 @@ void main() {
8484
});
8585

8686
test('Add counts for two days later', () async {
87-
final initialLastDate = DateTime.parse('1986-02-16');
87+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
8888
final countData = setupInitialCounts(initialLastDate);
8989

9090
// Extend existing counts and expel the lowest range.
@@ -186,7 +186,7 @@ void main() {
186186
});
187187

188188
test('Add counts on older date', () async {
189-
final initialLastDate = DateTime.parse('1986-02-16');
189+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
190190
final countData = setupInitialCounts(initialLastDate);
191191

192192
final versionsCounts = {
@@ -223,7 +223,7 @@ void main() {
223223
});
224224

225225
test('Add counts not affecting range', () async {
226-
final initialLastDate = DateTime.parse('1986-02-16');
226+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
227227
final countData = setupInitialCounts(initialLastDate);
228228

229229
final versionsCounts = {
@@ -257,7 +257,7 @@ void main() {
257257
});
258258

259259
test('Add counts on missing range in the middle', () async {
260-
final initialLastDate = DateTime.parse('1986-02-16');
260+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
261261
final countData = setupInitialCounts(initialLastDate);
262262

263263
final versionCounts = {
@@ -296,7 +296,7 @@ void main() {
296296
});
297297

298298
test('Add counts on missing range in the end', () async {
299-
final initialLastDate = DateTime.parse('1986-02-16');
299+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
300300

301301
final countData = CountData.empty();
302302
final versionsCounts = {
@@ -342,7 +342,7 @@ void main() {
342342
});
343343

344344
test('More than maxAge dates', () async {
345-
final initialLastDate = DateTime.parse('1986-02-16');
345+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
346346
final countData = CountData.empty();
347347
final versionsCounts = {
348348
'1.0.0': 2,

app/test/service/download_counts/download_counts_minor_test.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void main() {
5151
}
5252

5353
test('Add counts on following date', () async {
54-
final initialLastDate = DateTime.parse('1986-02-16');
54+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
5555
final countData = setupInitialCounts(initialLastDate);
5656

5757
// Extend existing counts and expel the lowest range.
@@ -94,7 +94,7 @@ void main() {
9494
});
9595

9696
test('Add counts for two days later', () async {
97-
final initialLastDate = DateTime.parse('1986-02-16');
97+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
9898
final countData = setupInitialCounts(initialLastDate);
9999

100100
// Extend existing counts and expel the lowest range.
@@ -211,7 +211,7 @@ void main() {
211211
});
212212

213213
test('Add counts on older date', () async {
214-
final initialLastDate = DateTime.parse('1986-02-16');
214+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
215215
final countData = setupInitialCounts(initialLastDate);
216216

217217
final versionsCounts = {
@@ -253,7 +253,7 @@ void main() {
253253
});
254254

255255
test('Add counts not affecting minor ranges', () async {
256-
final initialLastDate = DateTime.parse('1986-02-16');
256+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
257257
final countData = setupInitialCounts(initialLastDate);
258258

259259
final versionsCounts = {
@@ -297,7 +297,7 @@ void main() {
297297
});
298298

299299
test('Add counts on missing minor range in the middle', () async {
300-
final initialLastDate = DateTime.parse('1986-02-16');
300+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
301301
final countData = setupInitialCounts(initialLastDate);
302302

303303
final versionCounts = {
@@ -341,7 +341,7 @@ void main() {
341341
});
342342

343343
test('Add counts on missing minor range in the end', () async {
344-
final initialLastDate = DateTime.parse('1986-02-16');
344+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
345345

346346
final countData = CountData.empty();
347347
final versionsCounts = {
@@ -392,7 +392,7 @@ void main() {
392392
});
393393

394394
test('More than maxAge dates', () async {
395-
final initialLastDate = DateTime.parse('1986-02-16');
395+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
396396
final countData = CountData.empty();
397397
final versionsCounts = {
398398
'1.1.0': 2,

app/test/service/download_counts/download_counts_patch_test.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void main() {
5858
}
5959

6060
test('Add counts on following date', () async {
61-
final initialLastDate = DateTime.parse('1986-02-16');
61+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
6262
final countData = setupInitialCounts(initialLastDate);
6363

6464
// Extend existing counts and expel the lowest range.
@@ -108,7 +108,7 @@ void main() {
108108
});
109109

110110
test('Add counts for two days later', () async {
111-
final initialLastDate = DateTime.parse('1986-02-16');
111+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
112112
final countData = setupInitialCounts(initialLastDate);
113113

114114
// Extend existing counts and expel the lowest range.
@@ -246,7 +246,7 @@ void main() {
246246
});
247247

248248
test('Add counts on older date', () async {
249-
final initialLastDate = DateTime.parse('1986-02-16');
249+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
250250
final countData = setupInitialCounts(initialLastDate);
251251

252252
final versionsCounts = {
@@ -295,7 +295,7 @@ void main() {
295295
});
296296

297297
test('Add counts not affecting ranges', () async {
298-
final initialLastDate = DateTime.parse('1986-02-16');
298+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
299299
final countData = setupInitialCounts(initialLastDate);
300300

301301
final versionsCounts = {
@@ -351,7 +351,7 @@ void main() {
351351
});
352352

353353
test('Add counts on missing patch range in the middle', () async {
354-
final initialLastDate = DateTime.parse('1986-02-16');
354+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
355355
final countData = setupInitialCounts(initialLastDate);
356356

357357
final versionCounts = {
@@ -402,7 +402,7 @@ void main() {
402402
});
403403

404404
test('Add counts on missing patch range in the end', () async {
405-
final initialLastDate = DateTime.parse('1986-02-16');
405+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
406406

407407
final countData = CountData.empty();
408408
final versionsCounts = {
@@ -470,7 +470,7 @@ void main() {
470470
});
471471

472472
test('More than maxAge dates', () async {
473-
final initialLastDate = DateTime.parse('1986-02-16');
473+
final initialLastDate = DateTime.parse('1986-02-16T00:00:00Z');
474474
final countData = CountData.empty();
475475
final versionsCounts = {
476476
'1.1.0': 2,

app/test/service/download_counts/download_counts_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void main() {
3131
'4.0.0-0': 2,
3232
'6.1.0': 2,
3333
};
34-
final date = DateTime.parse('1986-02-16');
34+
final date = DateTime.parse('1986-02-16T00:00:00Z');
3535
final updatedDownloadCounts = await downloadCountsBackend
3636
.updateDownloadCounts(pkg, versionsCounts, date);
3737
expect(updatedDownloadCounts, isNotNull);
@@ -48,7 +48,7 @@ void main() {
4848
});
4949

5050
testWithProfile('process download counts', fn: () async {
51-
final date = DateTime.parse('2024-01-05');
51+
final date = DateTime.parse('2024-01-05T00:00:00Z');
5252
final downloadCountsJsonFileName =
5353
'daily_download_counts/2024-01-05T00:00:00Z/data-000000000000.jsonl';
5454
await uploadFakeDownloadCountsToBucket(
@@ -69,7 +69,7 @@ void main() {
6969
testWithProfile(
7070
'Process download counts - 0 count for unmentioned packages',
7171
fn: () async {
72-
final date = DateTime.parse('2024-01-05');
72+
final date = DateTime.parse('2024-01-05T00:00:00Z');
7373
final downloadCountsJsonFileNameJan5 =
7474
'daily_download_counts/2024-01-05T00:00:00Z/data-000000000000.jsonl';
7575
await uploadFakeDownloadCountsToBucket(
@@ -78,7 +78,7 @@ void main() {
7878
'download_counts', 'fake_download_counts_data.jsonl'));
7979
await processDownloadCounts(date);
8080

81-
final nextDate = DateTime.parse('2024-01-06');
81+
final nextDate = DateTime.parse('2024-01-06T00:00:00Z');
8282
final downloadCountsJsonFileNameJan6 =
8383
'daily_download_counts/2024-01-06T00:00:00Z/data-000000000000.jsonl';
8484
await uploadFakeDownloadCountsToBucket(
@@ -110,7 +110,7 @@ void main() {
110110
});
111111

112112
testWithProfile('with faulty line', fn: () async {
113-
final nextDate = DateTime.parse('2024-01-06');
113+
final nextDate = DateTime.parse('2024-01-06T00:00:00Z');
114114
final downloadCountsJsonFileNameJan6 =
115115
'daily_download_counts/2024-01-06T00:00:00Z/data-000000000000.jsonl';
116116
await uploadFakeDownloadCountsToBucket(
@@ -147,7 +147,7 @@ void main() {
147147
});
148148

149149
testWithProfile('with non-existing package', fn: () async {
150-
final nextDate = DateTime.parse('2024-01-06');
150+
final nextDate = DateTime.parse('2024-01-06T00:00:00Z');
151151
final downloadCountsJsonFileNameJan6 =
152152
'daily_download_counts/2024-01-06T00:00:00Z/data-000000000000.jsonl';
153153
await uploadFakeDownloadCountsToBucket(
@@ -182,7 +182,7 @@ void main() {
182182
});
183183

184184
testWithProfile('file not present', fn: () async {
185-
final nextDate = DateTime.parse('2024-01-06');
185+
final nextDate = DateTime.parse('2024-01-06T00:00:00Z');
186186
Set<String> failedFiles;
187187
final messages = <String>[];
188188
final subscription = Logger.root.onRecord.listen((event) {
@@ -199,7 +199,7 @@ void main() {
199199
});
200200

201201
testWithProfile('empty file', fn: () async {
202-
final nextDate = DateTime.parse('2024-01-06');
202+
final nextDate = DateTime.parse('2024-01-06T00:00:00Z');
203203
final downloadCountsJsonFileNameJan6 =
204204
'daily_download_counts/2024-01-06T00:00:00Z/data-000000000000.jsonl';
205205
await uploadFakeDownloadCountsToBucket(

0 commit comments

Comments
 (0)