Skip to content

Commit 6ce5b08

Browse files
authored
Download counts: fix date formatting in file name (#7840)
1 parent dbdfa8f commit 6ce5b08

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

app/lib/service/download_counts/sync_download_counts.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Future<void> syncDownloadCounts() async {
143143
final syncDate = today.addCalendarDays(-i);
144144
final fileName = [
145145
'daily_download_counts',
146-
'${syncDate.year}-${syncDate.month}-${syncDate.day}T00:00:00Z',
146+
formatDateForFileName(syncDate),
147147
'data-000000000000.jsonl',
148148
].join('/');
149149
final success = await processDownloadCounts(fileName, syncDate);
@@ -153,7 +153,7 @@ Future<void> syncDownloadCounts() async {
153153
}
154154
final yesterdayFileName = [
155155
'daily_download_counts',
156-
'${yesterday.year}-${yesterday.month}-${yesterday.day}T00:00:00Z',
156+
formatDateForFileName(yesterday),
157157
'data-000000000000.jsonl',
158158
].join('/');
159159

@@ -171,3 +171,9 @@ Future<void> syncDownloadCounts() async {
171171
}
172172
}
173173
}
174+
175+
String formatDateForFileName(DateTime date) {
176+
final month = date.month.toString().padLeft(2, '0');
177+
final day = date.day.toString().padLeft(2, '0');
178+
return '${date.year}-$month-${day}T00:00:00Z';
179+
}

app/test/service/download_counts/download_counts_test.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void main() {
202202
final date = today.addCalendarDays(-i);
203203
final fileName = [
204204
'daily_download_counts',
205-
'${date.year}-${date.month}-${date.day}T00:00:00Z',
205+
formatDateForFileName(date),
206206
'data-000000000000.jsonl',
207207
].join('/');
208208
await generateFakeDownloadCounts(
@@ -235,7 +235,7 @@ void main() {
235235
final date = today.addCalendarDays(-i);
236236
final fileName = [
237237
'daily_download_counts',
238-
'${date.year}-${date.month}-${date.day}T00:00:00Z',
238+
formatDateForFileName(date),
239239
'data-000000000000.jsonl',
240240
].join('/');
241241
await generateFakeDownloadCounts(
@@ -271,15 +271,14 @@ void main() {
271271
messages,
272272
contains('Failed to read '
273273
'"daily_download_counts/'
274-
'${yesterday.year}-${yesterday.month}-${yesterday.day}'
275-
'T00:00:00Z/data-000000000000.jsonl".'));
274+
'${formatDateForFileName(yesterday)}'
275+
'/data-000000000000.jsonl".'));
276276
expect(
277277
messages,
278278
contains(
279279
'Download counts sync was partial. The following files failed:\n'
280-
'[daily_download_counts/'
281-
'${yesterday.year}-${yesterday.month}-${yesterday.day}'
282-
'T00:00:00Z/data-000000000000.jsonl]'));
280+
'[daily_download_counts/${formatDateForFileName(yesterday)}'
281+
'/data-000000000000.jsonl]'));
283282
});
284283

285284
testWithProfile('Sync download counts - fail', fn: () async {
@@ -290,7 +289,7 @@ void main() {
290289
final date = today.addCalendarDays(-i);
291290
final fileName = [
292291
'daily_download_counts',
293-
'${date.year}-${date.month}-${date.day}T00:00:00Z',
292+
formatDateForFileName(date),
294293
'data-000000000000.jsonl',
295294
].join('/');
296295
await generateFakeDownloadCounts(
@@ -310,8 +309,8 @@ void main() {
310309
exception,
311310
'Exception: Download counts sync was partial. The following files failed:'
312311
'[daily_download_counts/'
313-
'${skippedDate.year}-${skippedDate.month}-${skippedDate.day}'
314-
'T00:00:00Z/data-000000000000.jsonl]');
312+
'${formatDateForFileName(skippedDate)}'
313+
'/data-000000000000.jsonl]');
315314

316315
final countData =
317316
await downloadCountsBackend.lookupDownloadCountData('neon');

0 commit comments

Comments
 (0)