Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match WHO Dashboard - Add one day to stats #1921

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions client/lib/api/who_date_format.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:intl/intl.dart';

extension WHOFormat on DateTime {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you wanted to write an extension ;-) I would've included the DateTime.fromMillisecondsSinceEpoch step also as that's common to both usages.... and it's the msSinceEpoch that has midnight ambiguity. By the time it's converted to a date, it should be correct, so doing +1 in the format step doesn't fit so well to me.

I would've just extracted a single method and not bothered with a new file. We can move it to a separate file if something else uses it. I think though that this formatting may be specific to the WHO dashboard.... no idea if it extends to the

String whoDashboardDateFormat(int epochMS) {
  var date = DateTime.fromMillisecondsSinceEpoch(epochMS);
  // Timestamps are for midnight so the day it applies to is ambiguous.
  // Add 1 day to match the WHO Dashboard: http://covid19.who.int
  date.add(Duration(days: 1))
  // Abbr to fit on single line: e.g. "Oct 18, 2020"
  return DateFormat.yMMMd().format(date);
}

String get whoFormat => DateFormat.yMMMd().format(
// Timestamps are for midnight so the day it applies to is ambiguous.
// Add 1 day to match the WHO Dashboard: http://covid19.who.int
add(
Duration(
days: 1,
),
),
);
}
11 changes: 5 additions & 6 deletions client/lib/components/recent_numbers_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:who_app/components/themed_text.dart';
import 'package:who_app/constants.dart';
import 'package:who_app/pages/main_pages/recent_numbers.dart';
import 'package:who_app/proto/api/who/who.pb.dart';
import 'package:who_app/api/who_date_format.dart';

const double padding = 30;
const Duration defaultSwapDuration = Duration(
Expand Down Expand Up @@ -75,7 +76,7 @@ class _RecentNumbersBarGraphState extends State<RecentNumbersBarGraph> {
final date = DateTime.fromMillisecondsSinceEpoch(
widget.timeseries[index].epochMsec.toInt());
// Abbr to fit on single line: e.g. "Oct 18, 2020"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move comment to the extension as the comment it common to both usages and not specific to line 78

final formattedDate = DateFormat.yMMMd().format(date);
final formattedDate = date.whoFormat;

final formattedCount = NumberFormat().format(barRodData.y);

Expand Down Expand Up @@ -269,11 +270,9 @@ class _RecentNumbersGraphState extends State<RecentNumbersGraph> {
if (epochsMilliseconds == null) {
return '';
} else {
return DateFormat.MMMd().format(
DateTime.fromMillisecondsSinceEpoch(
epochsMilliseconds,
),
);
return DateTime.fromMillisecondsSinceEpoch(
epochsMilliseconds,
).whoFormat;
}
}

Expand Down