Skip to content

Commit

Permalink
Fix year text on timescale
Browse files Browse the repository at this point in the history
  • Loading branch information
takenagain committed Feb 11, 2024
1 parent 5c1414e commit e0f7fa0
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/screens/markets/candlestick_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class _ChartPainter extends CustomPainter {
rightMarkerPosition - labelWidth - 4,
size.height - 7,
),
text: _formatTime(visibleCandlesData.first.closeTime * 1000),
text: _formatTime(visibleCandlesData.first.closeTime),
align: TextAlign.end,
width: labelWidth,
);
Expand All @@ -396,7 +396,7 @@ class _ChartPainter extends CustomPainter {
4,
size.height - 7,
),
text: _formatTime(visibleCandlesData.last.closeTime * 1000),
text: _formatTime(visibleCandlesData.last.closeTime),
align: TextAlign.start,
width: labelWidth,
);
Expand Down Expand Up @@ -485,7 +485,7 @@ class _ChartPainter extends CustomPainter {
align: TextAlign.center,
color: widget.textColor == Colors.black ? Colors.white : Colors.black,
backgroundColor: widget.textColor,
text: ' ${_formatTime(selectedCandle.closeTime * 1000)} ',
text: ' ${_formatTime(selectedCandle.closeTime)} ',
point: Offset(dx - 50, size.height - 7),
width: labelWidth,
);
Expand Down Expand Up @@ -569,16 +569,17 @@ class _ChartPainter extends CustomPainter {
String _formatTime(int millisecondsSinceEpoch) {
final DateTime utc = DateTime.fromMillisecondsSinceEpoch(
millisecondsSinceEpoch,
isUtc: false,
isUtc: true,
);
final bool thisYear = DateTime.now().year ==
DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch).year;
final bool thisYear = DateTime.now().year == utc.year;

String format = 'MMM dd yyyy';
if (widget.duration < 60 * 60 * 24)
if (widget.duration < 60 * 60 * 24) {
format = 'MMM dd${thisYear ? '' : ' yyyy'}, HH:00';
if (widget.duration < 60 * 60)
}
if (widget.duration < 60 * 60) {
format = 'MMM dd${thisYear ? '' : ' yyyy'}, HH:mm';
}

return DateFormat(format).format(utc);
}
Expand Down

0 comments on commit e0f7fa0

Please sign in to comment.