Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Gorshenin <y@maps.me>2017-06-21 17:29:17 +0300
committerYuri Gorshenin <mipt.vi002@gmail.com>2017-07-05 16:41:38 +0300
commit01dd3625451f70d6f3c81a202fc9db4e02d236d8 (patch)
tree68298ed841df3197075ad86f88c336e58cbf6016
parent7a57513d08adc9f91c221ca10df243e58377c0fb (diff)
[ugc] DaysAgo.
-rw-r--r--android/jni/com/mapswithme/maps/UGC.cpp2
-rw-r--r--android/src/com/mapswithme/maps/ugc/UGC.java10
-rw-r--r--android/src/com/mapswithme/maps/ugc/UGCReviewAdapter.java3
-rw-r--r--ugc/api.cpp10
-rw-r--r--ugc/types.hpp8
5 files changed, 20 insertions, 13 deletions
diff --git a/android/jni/com/mapswithme/maps/UGC.cpp b/android/jni/com/mapswithme/maps/UGC.cpp
index 66b48079d8..0eb0c8b2e3 100644
--- a/android/jni/com/mapswithme/maps/UGC.cpp
+++ b/android/jni/com/mapswithme/maps/UGC.cpp
@@ -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;
}
diff --git a/android/src/com/mapswithme/maps/ugc/UGC.java b/android/src/com/mapswithme/maps/ugc/UGC.java
index 6eb90dc4ec..0323035fba 100644
--- a/android/src/com/mapswithme/maps/ugc/UGC.java
+++ b/android/src/com/mapswithme/maps/ugc/UGC.java
@@ -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;
}
}
diff --git a/android/src/com/mapswithme/maps/ugc/UGCReviewAdapter.java b/android/src/com/mapswithme/maps/ugc/UGCReviewAdapter.java
index f42cebfbc0..fb26fa1ab0 100644
--- a/android/src/com/mapswithme/maps/ugc/UGCReviewAdapter.java
+++ b/android/src/com/mapswithme/maps/ugc/UGCReviewAdapter.java
@@ -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());
}
}
diff --git a/ugc/api.cpp b/ugc/api.cpp
index 550621162b..7750aceee9 100644
--- a/ugc/api.cpp
+++ b/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");
diff --git a/ugc/types.hpp b/ugc/types.hpp
index 4c57f6ec52..343f6d82c7 100644
--- a/ugc/types.hpp
+++ b/ugc/types.hpp
@@ -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;