void LLTeleportHistoryPanel::getNextTab(const LLDate& item_date, S32& tab_idx, LLDate& tab_date) { const U32 seconds_in_day = 24 * 60 * 60; S32 tabs_cnt = mItemContainers.size(); S32 curr_year = 0, curr_month = 0, curr_day = 0; tab_date = LLDate::now(); tab_date.split(&curr_year, &curr_month, &curr_day); tab_date.fromYMDHMS(curr_year, curr_month, curr_day); // Set hour, min, and sec to 0 tab_date.secondsSinceEpoch(tab_date.secondsSinceEpoch() + seconds_in_day); tab_idx = -1; while (tab_idx < tabs_cnt - 1 && item_date < tab_date) { tab_idx++; if (tab_idx <= tabs_cnt - 4) { // All tabs, except last three, are tabs for one day, so just push tab_date back by one day tab_date.secondsSinceEpoch(tab_date.secondsSinceEpoch() - seconds_in_day); } else if (tab_idx == tabs_cnt - 3) // 6 day and older, low boundary is 1 month { tab_date = LLDate::now(); tab_date.split(&curr_year, &curr_month, &curr_day); curr_month--; if (0 == curr_month) { curr_month = 12; curr_year--; } tab_date.fromYMDHMS(curr_year, curr_month, curr_day); } else if (tab_idx == tabs_cnt - 2) // 1 month and older, low boundary is 6 months { tab_date = LLDate::now(); tab_date.split(&curr_year, &curr_month, &curr_day); if (curr_month > 6) { curr_month -= 6; } else { curr_month += 6; curr_year--; } tab_date.fromYMDHMS(curr_year, curr_month, curr_day); } else // 6 months and older { tab_date.secondsSinceEpoch(0); } } }
std::string LLTeleportHistoryFlatItem::getTimestamp() { const LLDate &date = mDate; std::string timestamp = ""; LLDate now = LLDate::now(); S32 now_year, now_month, now_day, now_hour, now_min, now_sec; now.split(&now_year, &now_month, &now_day, &now_hour, &now_min, &now_sec); const S32 seconds_in_day = 24 * 60 * 60; S32 seconds_today = now_hour * 60 * 60 + now_min * 60 + now_sec; S32 time_diff = (S32) now.secondsSinceEpoch() - (S32) date.secondsSinceEpoch(); // Only show timestamp for today and yesterday if(time_diff < seconds_today + seconds_in_day) { timestamp = "[" + LLTrans::getString("TimeHour12")+"]:[" + LLTrans::getString("TimeMin")+"] ["+ LLTrans::getString("TimeAMPM")+"]"; LLSD substitution; substitution["datetime"] = (S32) date.secondsSinceEpoch(); LLStringUtil::format(timestamp, substitution); } return timestamp; }
std::string LLDateUtil::ageFromDate(const LLDate& born_date, const LLDate& now) { S32 born_month, born_day, born_year; // explode out to month/day/year again born_date.split(&born_year, &born_month, &born_day); S32 now_year, now_month, now_day; now.split(&now_year, &now_month, &now_day); // Do grade-school subtraction, from right-to-left, borrowing from the left // when things go negative S32 age_days = (now_day - born_day); if (age_days < 0) { now_month -= 1; if (now_month == 0) { now_year -= 1; now_month = 12; } age_days += days_from_month(now_year, now_month); } S32 age_months = (now_month - born_month); if (age_months < 0) { now_year -= 1; age_months += 12; } S32 age_years = (now_year - born_year); // Noun pluralization depends on language std::string lang = LLUI::getLanguage(); // Try for age in round number of years LLStringUtil::format_map_t args; if (age_months > 0 || age_years > 0) { args["[AGEYEARS]"] = LLTrans::getCountString(lang, "AgeYears", age_years); args["[AGEMONTHS]"] = LLTrans::getCountString(lang, "AgeMonths", age_months); // We want to display times like: // 2 year 2 months // 2 years (implicitly 0 months) // 11 months if (age_years > 0) { if (age_months > 0) { return LLTrans::getString("YearsMonthsOld", args); } else { return LLTrans::getString("YearsOld", args); } } else // age_years == 0 { return LLTrans::getString("MonthsOld", args); } } // you're 0 months old, display in weeks or days // Now for age in weeks S32 age_weeks = age_days / 7; age_days = age_days % 7; if (age_weeks > 0) { args["[AGEWEEKS]"] = LLTrans::getCountString(lang, "AgeWeeks", age_weeks); return LLTrans::getString("WeeksOld", args); } // Down to days now if (age_days > 0) { args["[AGEDAYS]"] = LLTrans::getCountString(lang, "AgeDays", age_days); return LLTrans::getString("DaysOld", args); } return LLTrans::getString("TodayOld"); }