diff options
author | James Cook <james@lindenlab.com> | 2010-02-23 16:33:43 -0800 |
---|---|---|
committer | James Cook <james@lindenlab.com> | 2010-02-23 16:33:43 -0800 |
commit | 305ec89a70bf88fce8f5edda15047182bc56682b (patch) | |
tree | fa81888317c907ed848ce3920dad724235e9778b /indra | |
parent | 087736c1522f111bc6a4d4937db8541031ef4014 (diff) |
Added ageFromDateISO() for YYYY-MM-DD dates
Diffstat (limited to 'indra')
-rw-r--r-- | indra/newview/lldateutil.cpp | 31 | ||||
-rw-r--r-- | indra/newview/lldateutil.h | 6 | ||||
-rw-r--r-- | indra/newview/tests/lldateutil_test.cpp | 10 |
3 files changed, 42 insertions, 5 deletions
diff --git a/indra/newview/lldateutil.cpp b/indra/newview/lldateutil.cpp index abb2fdeb9a..150edb5bf8 100644 --- a/indra/newview/lldateutil.cpp +++ b/indra/newview/lldateutil.cpp @@ -59,12 +59,9 @@ static S32 days_from_month(S32 year, S32 month) } } -std::string LLDateUtil::ageFromDate(const std::string& date_string, - const LLDate& now) +static std::string age_from_date(S32 born_year, S32 born_month, S32 born_day, + const LLDate& now) { - S32 born_month, born_day, born_year; - S32 matched = sscanf(date_string.c_str(), "%d/%d/%d", &born_month, &born_day, &born_year); - if (matched != 3) return "???"; LLDate born_date; born_date.fromYMDHMS(born_year, born_month, born_day); F64 born_date_secs_since_epoch = born_date.secondsSinceEpoch(); @@ -155,7 +152,31 @@ std::string LLDateUtil::ageFromDate(const std::string& date_string, return LLTrans::getString("TodayOld"); } +std::string LLDateUtil::ageFromDate(const std::string& date_string, + const LLDate& now) +{ + S32 born_month, born_day, born_year; + S32 matched = sscanf(date_string.c_str(), "%d/%d/%d", &born_month, &born_day, &born_year); + if (matched != 3) return "???"; + return age_from_date(born_year, born_month, born_day, now); +} + std::string LLDateUtil::ageFromDate(const std::string& date_string) { return ageFromDate(date_string, LLDate::now()); } + +std::string LLDateUtil::ageFromDateISO(const std::string& date_string, + const LLDate& now) +{ + S32 born_month, born_day, born_year; + S32 matched = sscanf(date_string.c_str(), "%d-%d-%d", + &born_year, &born_month, &born_day); + if (matched != 3) return "???"; + return age_from_date(born_year, born_month, born_day, now); +} + +std::string LLDateUtil::ageFromDateISO(const std::string& date_string) +{ + return ageFromDateISO(date_string, LLDate::now()); +} diff --git a/indra/newview/lldateutil.h b/indra/newview/lldateutil.h index 041be07f12..d077f4eefb 100644 --- a/indra/newview/lldateutil.h +++ b/indra/newview/lldateutil.h @@ -44,6 +44,12 @@ namespace LLDateUtil // Calls the above with LLDate::now() std::string ageFromDate(const std::string& date_string); + + // As above, for YYYY-MM-DD dates + std::string ageFromDateISO(const std::string& date_string, const LLDate& now); + + // Calls the above with LLDate::now() + std::string ageFromDateISO(const std::string& date_string); } #endif diff --git a/indra/newview/tests/lldateutil_test.cpp b/indra/newview/tests/lldateutil_test.cpp index 7ba82fbd2c..e19983db8f 100644 --- a/indra/newview/tests/lldateutil_test.cpp +++ b/indra/newview/tests/lldateutil_test.cpp @@ -189,4 +189,14 @@ namespace tut LLDateUtil::ageFromDate("12/13/2009", now), "3 weeks old" ); } + + template<> template<> + void dateutil_object_t::test<6>() + { + set_test_name("ISO dates"); + LLDate now(std::string("2010-01-04T12:00:00Z")); + ensure_equals("days", + LLDateUtil::ageFromDateISO("2009-12-13", now), + "3 weeks old" ); + } } |