forked from organicmaps/organicmaps
[ugc] DaysAgo.
This commit is contained in:
parent
7a57513d08
commit
01dd362545
5 changed files with 20 additions and 13 deletions
|
@ -113,7 +113,7 @@ private:
|
|||
jni::TScopedLocalRef text(env, jni::ToJavaString(env, review.m_text.m_text));
|
||||
jni::TScopedLocalRef author(env, jni::ToJavaString(env, review.m_author.m_name));
|
||||
jobject result = env->NewObject(m_reviewClass, m_reviewCtor, text.get(), author.get(),
|
||||
ugc::ToDaysSinceEpoch(review.m_time));
|
||||
static_cast<jlong>(ugc::DaysAgo(review.m_time)));
|
||||
ASSERT(result, ());
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -107,13 +107,13 @@ public class UGC implements Serializable
|
|||
private final String mText;
|
||||
@NonNull
|
||||
private final String mAuthor;
|
||||
private final long mTime;
|
||||
private final long mDaysAgo;
|
||||
|
||||
private Review(@NonNull String text, @NonNull String author, long time)
|
||||
private Review(@NonNull String text, @NonNull String author, long daysAgo)
|
||||
{
|
||||
mText = text;
|
||||
mAuthor = author;
|
||||
mTime = time;
|
||||
mDaysAgo = daysAgo;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -128,9 +128,9 @@ public class UGC implements Serializable
|
|||
return mAuthor;
|
||||
}
|
||||
|
||||
public long getTime()
|
||||
public long getDaysAgo()
|
||||
{
|
||||
return mTime;
|
||||
return mDaysAgo;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,8 +73,7 @@ public class UGCReviewAdapter extends Adapter<UGCReviewAdapter.ViewHolder>
|
|||
{
|
||||
UiUtils.showIf(isShowDivider, mDivider);
|
||||
mAuthor.setText(review.getAuthor());
|
||||
Date date = new Date(review.getTime());
|
||||
mCommentDate.setText(DateFormat.getMediumDateFormat(mCommentDate.getContext()).format(date));
|
||||
mCommentDate.setText(review.getDaysAgo() + " days ago");
|
||||
mReview.setText(review.getText());
|
||||
}
|
||||
}
|
||||
|
|
10
ugc/api.cpp
10
ugc/api.cpp
|
@ -9,9 +9,9 @@ using namespace ugc;
|
|||
|
||||
namespace
|
||||
{
|
||||
chrono::hours FromDays(uint32_t days)
|
||||
Time FromDaysAgo(uint32_t days)
|
||||
{
|
||||
return std::chrono::hours(days * 24);
|
||||
return std::chrono::system_clock::now() - std::chrono::hours(days * 24);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
@ -46,11 +46,11 @@ UGC Api::MakeTestUGC1()
|
|||
vector<Review> reviews;
|
||||
reviews.emplace_back(20 /* id */, Text("Damn good coffee", StringUtf8Multilang::kEnglishCode),
|
||||
Author(UID(987654321 /* hi */, 123456789 /* lo */), "Cole"),
|
||||
5.0 /* rating */, Sentiment::Positive, Time(FromDays(10)));
|
||||
5.0 /* rating */, Sentiment::Positive, FromDaysAgo(10));
|
||||
reviews.emplace_back(67812 /* id */,
|
||||
Text("Clean place, reasonably priced", StringUtf8Multilang::kDefaultCode),
|
||||
Author(UID(0 /* hi */, 315 /* lo */), "Cooper"), 5.0 /* rating */,
|
||||
Sentiment::Positive, Time(FromDays(1)));
|
||||
Sentiment::Positive, FromDaysAgo(1));
|
||||
|
||||
vector<Attribute> attributes;
|
||||
attributes.emplace_back("best-drink", "Coffee");
|
||||
|
@ -71,7 +71,7 @@ UGC Api::MakeTestUGC2()
|
|||
reviews.emplace_back(119 /* id */,
|
||||
Text("This pie's so good it is a crime", StringUtf8Multilang::kDefaultCode),
|
||||
Author(UID(0 /* hi */, 315 /* lo */), "Cooper"), 5.0 /* rating */,
|
||||
Sentiment::Positive, Time(FromDays(1)));
|
||||
Sentiment::Positive, FromDaysAgo(1));
|
||||
|
||||
vector<Attribute> attributes;
|
||||
attributes.emplace_back("best-drink", "Coffee");
|
||||
|
|
|
@ -56,6 +56,14 @@ inline Time FromDaysSinceEpoch(uint32_t days)
|
|||
return Time(hours);
|
||||
}
|
||||
|
||||
inline uint32_t DaysAgo(Time const & time)
|
||||
{
|
||||
auto const now = std::chrono::system_clock::now();
|
||||
if (now < time)
|
||||
return 0;
|
||||
return std::chrono::duration_cast<std::chrono::hours>(now - time).count() / 24;
|
||||
}
|
||||
|
||||
struct RatingRecord
|
||||
{
|
||||
RatingRecord() = default;
|
||||
|
|
Loading…
Add table
Reference in a new issue