mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-21 05:43:37 +00:00
[android] Add support for check_date & check_date:opening_hours
Signed-off-by: Harry Bond <me@hbond.xyz>
This commit is contained in:
@@ -68,7 +68,9 @@ public class Metadata implements Parcelable
|
||||
FMD_NETWORK(49),
|
||||
FMD_CONTACT_FEDIVERSE(50),
|
||||
FMD_CONTACT_BLUESKY(51),
|
||||
FMD_PANORAMAX(52);
|
||||
FMD_PANORAMAX(52),
|
||||
FMD_CHECK_DATE(53),
|
||||
FMD_CHECK_DATE_OPEN_HOURS(54);
|
||||
private final int mMetaType;
|
||||
|
||||
MetadataType(int metadataType)
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package app.organicmaps.sdk.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.NonNull;
|
||||
import java.text.DateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Locale;
|
||||
|
||||
import app.organicmaps.R;
|
||||
|
||||
public final class DateUtils
|
||||
{
|
||||
private DateUtils() {}
|
||||
@@ -23,4 +29,29 @@ public final class DateUtils
|
||||
{
|
||||
return android.text.format.DateFormat.is24HourFormat(context);
|
||||
}
|
||||
|
||||
/***
|
||||
* @param dateString Date string in the yyyy-MM-dd format
|
||||
* @return Human-readable string of the time that's passed since the date
|
||||
*/
|
||||
public static String getRelativePeriodString(Resources resources, String dateString)
|
||||
{
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
int days = (int) (LocalDate.now().toEpochDay() - LocalDate.parse(dateString, formatter).toEpochDay());
|
||||
|
||||
if (days == 0)
|
||||
return resources.getString(R.string.today);
|
||||
if (days == 1)
|
||||
return resources.getString(R.string.yesterday);
|
||||
if (days < 7)
|
||||
return resources.getString(R.string.days_ago, Integer.toString(days));
|
||||
if (days < 30)
|
||||
return resources.getString(days < 14 ? R.string.week_ago : R.string.weeks_ago, Integer.toString(days / 7));
|
||||
if (days < 365)
|
||||
return resources.getString(days < 60 ? R.string.month_ago : R.string.months_ago, Integer.toString(days / 30));
|
||||
if (days > 365)
|
||||
return resources.getString(days < 730 ? R.string.year_ago : R.string.years_ago, Integer.toString(days / 365));
|
||||
else
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user