SystemUptime.fromJson constructor

SystemUptime.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory SystemUptime.fromJson(Map<String, dynamic> json) {
  final bootTime = (json['bootTime'] as num?)?.toDouble() ?? 0.0;
  final uptime = (json['uptime'] as num?)?.toDouble() ?? 0.0;

  final bootDate = bootTime > 0
      ? DateTime.fromMillisecondsSinceEpoch((bootTime * 1000).toInt())
      : DateTime.now().subtract(Duration(seconds: uptime.toInt()));

  final uptimeFormatted =
      json['uptimeFormatted'] as String? ?? _formatUptime(uptime);

  return SystemUptime(
    bootTime: bootTime,
    uptime: uptime,
    uptimeFormatted: uptimeFormatted,
    bootDate: bootDate,
  );
}