Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ class ViewsAndVisitorsMapper
Visitors -> it.visitors
else -> 0L
}
val date = statsDateFormatter.parseStatsDate(statsGranularity, it.period)
Line(
statsDateFormatter.printGranularDate(it.period, statsGranularity),
statsDateFormatter.printDayWithoutYear(date),
it.period,
value.toInt()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ package org.wordpress.android.ui.stats.refresh.utils
import com.github.mikephil.charting.components.AxisBase
import com.github.mikephil.charting.formatter.ValueFormatter
import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.LineChartItem.Line
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import javax.inject.Inject

class LineChartLabelFormatter @Inject constructor(
Expand All @@ -15,27 +11,9 @@ class LineChartLabelFormatter @Inject constructor(
override fun getAxisLabel(value: Float, axis: AxisBase?): String {
val index = value.toInt()
return if (index < entries.size) {
formatLabelDate(parseLabelDate(entries[index].label))
entries[index].label
} else {
""
}
}

// 12 Apr 2022
private fun parseLabelDate(label: String): Date? {
var labelDate: Date? = null
val labelParser = SimpleDateFormat("dd MMM yyyy", Locale.getDefault())
try {
labelDate = labelParser.parse(label)
} catch (e: ParseException) {
e.printStackTrace()
}
return labelDate
}

// Apr 12
private fun formatLabelDate(date: Date?): String {
val labelFormatter = SimpleDateFormat("MMM d", Locale.getDefault())
return date?.let { labelFormatter.format(it) }.toString()
}
}