Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the UtcDate class with DateUtil method calls. #3903

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class AggregatedFeedContentClient {

private fun requestAggregated() {
aggregatedClient.clientJob?.cancel()
val date = DateUtil.getUtcRequestDateFor(age)
val (year, month, day) = DateUtil.getYearMonthAndDayForAge(age)
aggregatedClient.clientJob = CoroutineScope(Dispatchers.Default).launch(
CoroutineExceptionHandler { _, caught ->
L.v(caught)
Expand All @@ -151,7 +151,7 @@ class AggregatedFeedContentClient {
FeedContentType.aggregatedLanguages.forEach { langCode ->
val wikiSite = WikiSite.forLanguageCode(langCode)
val hasParentLanguageCode = !WikipediaApp.instance.languageState.getDefaultLanguageCode(langCode).isNullOrEmpty()
var feedContentResponse = ServiceFactory.getRest(wikiSite).getFeedFeatured(date.year, date.month, date.day)
var feedContentResponse = ServiceFactory.getRest(wikiSite).getFeedFeatured(year, month, day)

// TODO: This is a temporary fix for T355192
if (hasParentLanguageCode) {
Expand Down
18 changes: 0 additions & 18 deletions app/src/main/java/org/wikipedia/feed/model/UtcDate.kt

This file was deleted.

9 changes: 2 additions & 7 deletions app/src/main/java/org/wikipedia/feed/news/NewsCard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package org.wikipedia.feed.news
import org.wikipedia.R
import org.wikipedia.dataclient.WikiSite
import org.wikipedia.feed.model.CardType
import org.wikipedia.feed.model.UtcDate
import org.wikipedia.feed.model.WikiSiteCard
import org.wikipedia.util.DateUtil
import org.wikipedia.util.L10nUtil
import java.util.concurrent.TimeUnit

class NewsCard(private val news: List<NewsItem>,
private val age: Int,
Expand All @@ -21,11 +20,7 @@ class NewsCard(private val news: List<NewsItem>,
}

override fun dismissHashCode(): Int {
return TimeUnit.MILLISECONDS.toDays(date().baseCalendar.time.time).toInt() + wikiSite().hashCode()
}

fun date(): UtcDate {
return UtcDate(age)
return DateUtil.getRequestDateForAge(age).toEpochDay().toInt() + wikiSite().hashCode()
}

fun news(): List<NewsItem> {
Expand Down
11 changes: 7 additions & 4 deletions app/src/main/java/org/wikipedia/util/DateUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.os.Build
import android.text.format.DateFormat
import org.wikipedia.R
import org.wikipedia.WikipediaApp
import org.wikipedia.feed.model.UtcDate
import java.text.SimpleDateFormat
import java.time.Instant
import java.time.LocalDate
Expand Down Expand Up @@ -45,7 +44,7 @@ object DateUtil {
}

fun getFeedCardDateString(age: Int): String {
return getShortDateString(UtcDate(age).baseCalendar.time)
return getShortDateString(getRequestDateForAge(age))
}

fun getFeedCardShortDateString(date: Calendar): String {
Expand Down Expand Up @@ -150,8 +149,12 @@ object DateUtil {
return DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).format(localDate)
}

fun getUtcRequestDateFor(age: Int): UtcDate {
return UtcDate(age)
fun getRequestDateForAge(age: Int): LocalDate {
return LocalDate.now().minusDays(age.toLong())
}

fun getYearMonthAndDayForAge(age: Int): List<String> {
return getRequestDateForAge(age).toString().split("-")
}

fun getDefaultDateFor(age: Int): Calendar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class WidgetFeaturedPageWorker(
return try {
val app = WikipediaApp.instance
val mainPageTitle = PageTitle(MainPageNameData.valueFor(app.appOrSystemLanguageCode), app.wikiSite)
val date = DateUtil.getUtcRequestDateFor(0)
val (year, month, day) = DateUtil.getYearMonthAndDayForAge(0)

val result = ServiceFactory.getRest(WikipediaApp.instance.wikiSite)
.getFeedFeatured(date.year, date.month, date.day)
.getFeedFeatured(year, month, day)

// TODO: don't use PageSummary.
val summary = if (result.tfa != null) {
Expand Down