Skip to content

Commit

Permalink
Change the epoch timestamp unit from seconds to milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
h65wang committed Jul 19, 2021
1 parent ae82aef commit a9ef15d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
1 change: 0 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class _MyAppState extends State<MyApp> {
"高": "${candle.high?.toStringAsFixed(2)}",
"低": "${candle.low?.toStringAsFixed(2)}",
},
timeLabel: (timestamp, count) => "<Date>",
priceLabel: (price) => "${price.round()} 💎",
),
),
Expand Down
2 changes: 1 addition & 1 deletion example/lib/mock_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ class MockDataTesla {

static List<CandleData> get candles => _rawData
.map((row) => CandleData(
timestamp: row[0],
timestamp: row[0] * 1000,
open: row[1]?.toDouble(),
high: row[2]?.toDouble(),
low: row[3]?.toDouble(),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/interactive_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class _InteractiveChartState extends State<InteractiveChart> {
}

String defaultTimeLabel(int timestamp, int visibleDataCount) {
final date = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000)
final date = DateTime.fromMillisecondsSinceEpoch(timestamp)
.toIso8601String()
.split("T")
.first
Expand All @@ -266,7 +266,7 @@ class _InteractiveChartState extends State<InteractiveChart> {

Map<String, String> defaultOverlayInfo(CandleData candle) {
final date = intl.DateFormat.yMMMd()
.format(DateTime.fromMillisecondsSinceEpoch(candle.timestamp * 1000));
.format(DateTime.fromMillisecondsSinceEpoch(candle.timestamp));
return {
"Date": date,
"Open": candle.open?.toStringAsFixed(2) ?? "-",
Expand Down

0 comments on commit a9ef15d

Please sign in to comment.