统计页重构:去掉顶部区间筛选,分布卡新增日/周/月/年与翻页,环形图改为引线标注并显示时长
This commit is contained in:
@@ -30,23 +30,52 @@ object Dates {
|
||||
|
||||
fun todayStart(): Long = dayStart(System.currentTimeMillis())
|
||||
|
||||
/** 本周一 00:00(周一为一周起点,符合国内习惯) */
|
||||
fun weekStart(): Long {
|
||||
/** 本周一 00:00(周一为一周起点,符合国内习惯);传任意时刻则返回它所在周的周一 */
|
||||
fun weekStart(ms: Long = System.currentTimeMillis()): Long {
|
||||
val c = Calendar.getInstance()
|
||||
c.timeInMillis = todayStart()
|
||||
c.timeInMillis = dayStart(ms)
|
||||
val dow = c.get(Calendar.DAY_OF_WEEK) // 1=周日
|
||||
val back = if (dow == Calendar.SUNDAY) 6 else dow - 2
|
||||
c.add(Calendar.DAY_OF_MONTH, -back)
|
||||
return c.timeInMillis
|
||||
}
|
||||
|
||||
fun monthStart(): Long {
|
||||
/** 所在月的 1 日 00:00;不传参就是本月 */
|
||||
fun monthStart(ms: Long = System.currentTimeMillis()): Long {
|
||||
val c = Calendar.getInstance()
|
||||
c.timeInMillis = todayStart()
|
||||
c.timeInMillis = dayStart(ms)
|
||||
c.set(Calendar.DAY_OF_MONTH, 1)
|
||||
return c.timeInMillis
|
||||
}
|
||||
|
||||
/** 所在年的 1 月 1 日 00:00;不传参就是今年 */
|
||||
fun yearStart(ms: Long = System.currentTimeMillis()): Long {
|
||||
val c = Calendar.getInstance()
|
||||
c.timeInMillis = dayStart(ms)
|
||||
c.set(Calendar.DAY_OF_MONTH, 1)
|
||||
c.set(Calendar.MONTH, Calendar.JANUARY)
|
||||
return c.timeInMillis
|
||||
}
|
||||
|
||||
fun addYears(ms: Long, years: Int): Long {
|
||||
val c = Calendar.getInstance()
|
||||
c.timeInMillis = ms
|
||||
c.add(Calendar.YEAR, years)
|
||||
return c.timeInMillis
|
||||
}
|
||||
|
||||
fun yearOf(ms: Long): Int {
|
||||
val c = Calendar.getInstance()
|
||||
c.timeInMillis = ms
|
||||
return c.get(Calendar.YEAR)
|
||||
}
|
||||
|
||||
fun monthOf(ms: Long): Int {
|
||||
val c = Calendar.getInstance()
|
||||
c.timeInMillis = ms
|
||||
return c.get(Calendar.MONTH) + 1
|
||||
}
|
||||
|
||||
fun addDays(ms: Long, days: Int): Long {
|
||||
val c = Calendar.getInstance()
|
||||
c.timeInMillis = ms
|
||||
@@ -80,6 +109,20 @@ object Dates {
|
||||
return if (m == 0) "${h}小时" else "${h}小时${m}分"
|
||||
}
|
||||
|
||||
/**
|
||||
* 环形图标注用的紧凑口径:20m / 1h 10m / 4h 3m。
|
||||
* 参考图里贴着引线的数字要一眼读出分量,中文"小时/分"太长会把标注撑到环外。
|
||||
*/
|
||||
fun durationBrief(seconds: Int): String {
|
||||
if (seconds <= 0) return "0m"
|
||||
val minutes = seconds / 60
|
||||
if (minutes <= 0) return "${seconds}s"
|
||||
if (minutes < 60) return "${minutes}m"
|
||||
val h = minutes / 60
|
||||
val m = minutes % 60
|
||||
return if (m == 0) "${h}h" else "${h}h ${m}m"
|
||||
}
|
||||
|
||||
/** 图表坐标轴用的短格式:2h / 45m */
|
||||
fun shortDuration(seconds: Int): String {
|
||||
if (seconds <= 0) return "0"
|
||||
|
||||
Reference in New Issue
Block a user