I am using SimpleDateFormat in my ViewModel to format some data. As you can see this way is not flexible because I couldn't change my format pattern whenever I want. What should I do to improve this ?
class DateFormat @Inject constructor() : SimpleDateFormat("EEE, MMM dd", Locale.US) {
fun convertUnixTimeToDate(unixTime: Long): String {
return try {
val date = Date(unixTime * 1000)
this.format(date)
} catch (e: NumberFormatException) {
e.toString()
}
}
}
@HiltViewModel
class WeatherViewModel @Inject constructor(
private val repository: WeatherRepository,
) : ViewModel() {
@Inject
lateinit var dateFormat: DateFormat