Created
August 2, 2024 04:09
-
-
Save devrath/a51fd45bf3e8b5333aa26d14955f876f to your computer and use it in GitHub Desktop.
TimeStamp centralized class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object SimpleDateFormatProvider { | |
private const val FORMAT_TIMESTAMP_1 = "yyyy-MM-dd'T'HH:mm:ss'Z'" | |
private const val FORMAT_TIMESTAMP_2 = "MMM d yyyy" | |
private const val FORMAT_TIMESTAMP_3 = "yyyy-MM-dd'T'HH:mm:ss.SSSX" | |
private const val FORMAT_TIMESTAMP_4 = "yyyy-MM-dd" | |
private const val FORMAT_TIMESTAMP_5 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" | |
private const val FORMAT_TIMESTAMP_6 = "yyyyMMdd" | |
fun getSimpleDateFormat(type: TimestampType): SimpleDateFormat { | |
return when (type) { | |
TimestampType.Timestamp1 -> { | |
SimpleDateFormat(FORMAT_TIMESTAMP_1, Locale.getDefault()) | |
} | |
TimestampType.Timestamp2 -> { | |
SimpleDateFormat(FORMAT_TIMESTAMP_2, Locale.getDefault()) | |
} | |
TimestampType.Timestamp3 -> { | |
SimpleDateFormat(FORMAT_TIMESTAMP_3, Locale.getDefault()) | |
} | |
TimestampType.Timestamp4 -> { | |
SimpleDateFormat(FORMAT_TIMESTAMP_4, Locale.getDefault()) | |
} | |
TimestampType.Timestamp5 -> { | |
SimpleDateFormat(FORMAT_TIMESTAMP_5, Locale.getDefault()) | |
} | |
TimestampType.Timestamp6 -> { | |
SimpleDateFormat(FORMAT_TIMESTAMP_6, Locale.getDefault()) | |
} | |
} | |
} | |
sealed interface TimestampType { | |
/** | |
* Date format "yyyy-MM-dd'T'HH:mm:ss'Z'" | |
* References [SimpleDateFormatProvider.FORMAT_TIMESTAMP_1] | |
*/ | |
data object Timestamp1 : TimestampType | |
/** | |
* Date format "MMM d yyyy" | |
* References [SimpleDateFormatProvider.FORMAT_TIMESTAMP_2] | |
*/ | |
data object Timestamp2 : TimestampType | |
/** | |
* Date format "yyyy-MM-dd'T'HH:mm:ss.SSSX" | |
* References [SimpleDateFormatProvider.FORMAT_TIMESTAMP_1] | |
*/ | |
data object Timestamp3 : TimestampType | |
/** | |
* Date format "yyyy-MM-dd" | |
* References [SimpleDateFormatProvider.FORMAT_TIMESTAMP_4] | |
*/ | |
data object Timestamp4 : TimestampType | |
/** | |
* Date format "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" | |
* References [SimpleDateFormatProvider.FORMAT_TIMESTAMP_5] | |
*/ | |
data object Timestamp5 : TimestampType | |
/** | |
* Date format "yyyyMMdd" | |
* References [SimpleDateFormatProvider.FORMAT_TIMESTAMP_5] | |
*/ | |
data object Timestamp6 : TimestampType | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment