diff options
Diffstat (limited to 'indra/newview/lllogchat.cpp')
-rw-r--r-- | indra/newview/lllogchat.cpp | 136 |
1 files changed, 114 insertions, 22 deletions
diff --git a/indra/newview/lllogchat.cpp b/indra/newview/lllogchat.cpp index f13445fa5d..f5f4feeab3 100644 --- a/indra/newview/lllogchat.cpp +++ b/indra/newview/lllogchat.cpp @@ -2,31 +2,25 @@ * @file lllogchat.cpp * @brief LLLogChat class implementation * - * $LicenseInfo:firstyear=2002&license=viewergpl$ - * - * Copyright (c) 2002-2009, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2002&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 + * Copyright (C) 2010, Linden Research, Inc. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at - * http://secondlifegrid.net/programs/open_source/licensing/flossexception + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -39,12 +33,27 @@ #include "llviewercontrol.h" #include "llinstantmessage.h" +#include "llsingleton.h" // for LLSingleton #include <boost/algorithm/string/trim.hpp> #include <boost/algorithm/string/replace.hpp> #include <boost/regex.hpp> #include <boost/regex/v4/match_results.hpp> +#if LL_MSVC +// disable warning about boost::lexical_cast unreachable code +// when it fails to parse the string +#pragma warning (disable:4702) +#endif + +#include <boost/date_time/gregorian/gregorian.hpp> +#if LL_MSVC +#pragma warning(pop) // Restore all warnings to the previous state +#endif + +#include <boost/date_time/posix_time/posix_time.hpp> +#include <boost/date_time/local_time_adjustor.hpp> + const S32 LOG_RECALL_SIZE = 2048; const static std::string IM_TIME("time"); @@ -83,11 +92,93 @@ const static boost::regex NAME_AND_TEXT("(You:|Second Life:|[^\\s:]+\\s*[:]{1}|\ //is used to parse complex object names like "Xstreet SL Terminal v2.2.5 st" const static std::string NAME_TEXT_DIVIDER(": "); +// is used for timestamps adjusting +const static char* DATE_FORMAT("%Y/%m/%d %H:%M"); +const static char* TIME_FORMAT("%H:%M"); + const static int IDX_TIMESTAMP = 1; const static int IDX_STUFF = 2; const static int IDX_NAME = 1; const static int IDX_TEXT = 3; +using namespace boost::posix_time; +using namespace boost::gregorian; + +class LLLogChatTimeScanner: public LLSingleton<LLLogChatTimeScanner> +{ +public: + LLLogChatTimeScanner() + { + // Note, date/time facets will be destroyed by string streams + mDateStream.imbue(std::locale(mDateStream.getloc(), new date_input_facet(DATE_FORMAT))); + mTimeStream.imbue(std::locale(mTimeStream.getloc(), new time_facet(TIME_FORMAT))); + mTimeStream.imbue(std::locale(mTimeStream.getloc(), new time_input_facet(DATE_FORMAT))); + } + + date getTodayPacificDate() + { + typedef boost::date_time::local_adjustor<ptime, -8, no_dst> pst; + typedef boost::date_time::local_adjustor<ptime, -7, no_dst> pdt; + time_t t_time = time(NULL); + ptime p_time = LLStringOps::getPacificDaylightTime() + ? pdt::utc_to_local(from_time_t(t_time)) + : pst::utc_to_local(from_time_t(t_time)); + struct tm s_tm = to_tm(p_time); + return date_from_tm(s_tm); + } + + void checkAndCutOffDate(std::string& time_str) + { + // Cuts off the "%Y/%m/%d" from string for todays timestamps. + // Assume that passed string has at least "%H:%M" time format. + date log_date(not_a_date_time); + date today(getTodayPacificDate()); + + // Parse the passed date + mDateStream.str(LLStringUtil::null); + mDateStream << time_str; + mDateStream >> log_date; + mDateStream.clear(); + + days zero_days(0); + days days_alive = today - log_date; + + if ( days_alive == zero_days ) + { + // Yep, today's so strip "%Y/%m/%d" info + ptime stripped_time(not_a_date_time); + + mTimeStream.str(LLStringUtil::null); + mTimeStream << time_str; + mTimeStream >> stripped_time; + mTimeStream.clear(); + + time_str.clear(); + + mTimeStream.str(LLStringUtil::null); + mTimeStream << stripped_time; + mTimeStream >> time_str; + mTimeStream.clear(); + } + + LL_DEBUGS("LLChatLogParser") + << " log_date: " + << log_date + << " today: " + << today + << " days alive: " + << days_alive + << " new time: " + << time_str + << LL_ENDL; + } + + +private: + std::stringstream mDateStream; + std::stringstream mTimeStream; +}; + //static std::string LLLogChat::makeLogFileName(std::string filename) { @@ -377,7 +468,8 @@ bool LLChatLogParser::parse(std::string& raw, LLSD& im) boost::trim(timestamp); timestamp.erase(0, 1); timestamp.erase(timestamp.length()-1, 1); - im[IM_TIME] = timestamp; + LLLogChatTimeScanner::instance().checkAndCutOffDate(timestamp); + im[IM_TIME] = timestamp; } else { |