Commit 715f99ac authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Get the day of week using the API (yes!!!)

parent c743db76
import android.content.Context
import chat.rocket.android.R
import org.threeten.bp.DayOfWeek
import org.threeten.bp.LocalDate
import org.threeten.bp.LocalDateTime
import org.threeten.bp.Period
import org.threeten.bp.format.DateTimeFormatter
import org.threeten.bp.format.FormatStyle
import org.threeten.bp.format.TextStyle
import org.threeten.bp.temporal.ChronoUnit
import java.util.*
object DateTimeHelper {
private val today = LocalDate.now()
......@@ -14,12 +15,11 @@ object DateTimeHelper {
private val lastWeek = today.minus(1, ChronoUnit.WEEKS)
/**
* Returns a date or the correlated expression from a LocalDateTime.
* REMARK: this will return "today", "yesterday", the day of the week or the localDate if the LocalDateTime is from a week ago.
* Returns a date from a LocalDateTime or the textual representation if the LocalDateTime has a max period of a week from the current date.
*
* @param localDateTime The LocalDateTime.
* @param context The context.
* @return The date or the correlated expression from a LocalDateTime.
* @return The date or the textual representation from a LocalDateTime.
*/
fun getDate(localDateTime: LocalDateTime, context: Context): String {
val localDate = localDateTime.toLocalDate()
......@@ -30,15 +30,7 @@ object DateTimeHelper {
if (Period.between(lastWeek, localDate).days <= 0) {
formatDate(localDate)
} else {
when (localDateTime.dayOfWeek) {
DayOfWeek.MONDAY -> context.getString(R.string.msg_monday)
DayOfWeek.TUESDAY -> context.getString(R.string.msg_tuesday)
DayOfWeek.WEDNESDAY -> context.getString(R.string.msg_wednesday)
DayOfWeek.THURSDAY -> context.getString(R.string.msg_thursday)
DayOfWeek.FRIDAY -> context.getString(R.string.msg_friday)
DayOfWeek.SATURDAY -> context.getString(R.string.msg_saturday)
else -> context.getString(R.string.msg_sunday)
}
localDate.dayOfWeek.getDisplayName(TextStyle.FULL, Locale.getDefault())
}
}
}
......
......@@ -20,13 +20,6 @@
<string name="msg_new_user_agreement">Ao proceder você concorda com nossos\n<font color='#FF1976D2'>Termos de Serviço</font> e <font color='#FF1976D2'>Política de Privacidade</font></string>
<string name="msg_2fa_code">Código 2FA</string>
<string name="msg_yesterday">ontem</string>
<string name="msg_monday">seg</string>
<string name="msg_tuesday">ter</string>
<string name="msg_wednesday">qua</string>
<string name="msg_thursday">qui</string>
<string name="msg_friday">sex</string>
<string name="msg_saturday">sab</string>
<string name="msg_sunday">dom</string>
<string name="msg_content_description_log_in_using_facebook">Fazer login através do Facebook</string>
<string name="msg_content_description_log_in_using_github">Fazer login através do Github</string>
<string name="msg_content_description_log_in_using_google">Fazer login através do Google</string>
......
......@@ -22,13 +22,6 @@
<string name="msg_2fa_code">2FA Code</string>
<string name="msg_more_than_ninety_nine_unread_messages" translatable="false">99+</string>
<string name="msg_yesterday">Yesterday</string>
<string name="msg_monday">Mon</string>
<string name="msg_tuesday">Tue</string>
<string name="msg_wednesday">Wed</string>
<string name="msg_thursday">Thu</string>
<string name="msg_friday">Fri</string>
<string name="msg_saturday">Sat</string>
<string name="msg_sunday">Sun</string>
<string name="msg_content_description_log_in_using_facebook">Login using Facebook</string>
<string name="msg_content_description_log_in_using_github">Login using Github</string>
<string name="msg_content_description_log_in_using_google">Login using Google</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment