From dd1d850e9396e8af8f6f63eda6e01bbb07704220 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Tue, 5 Jul 2005 09:01:52 +0000 Subject: [PATCH] localize date/time git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10129 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 5 +++++ src/frontends/controllers/ChangeLog | 5 +++++ src/frontends/controllers/ControlChanges.C | 8 ++----- src/support/ChangeLog | 5 +++++ src/support/lyxtime.C | 18 +++++++++++++++ src/support/lyxtime.h | 15 +++++++++++++ src/text3.C | 26 ++++++---------------- 7 files changed, 57 insertions(+), 25 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index eb6a546816..e808f38fdb 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2005-07-05 Jürgen Spitzmüller + + * text3.C (doDispatch): rewrite LFUN_DATE_INSERT using the brandnew + formatted_time methods in support/lyxtime. + 2005-07-04 Jürgen Spitzmüller * toc.[Ch]: new method getGuiName, which is used by the frontends diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index aa550a4749..204eeebf87 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,8 @@ +2005-07-05 Jürgen Spitzmüller + + * ControlChanges.C (getChangeDate): use localized date (from + support/lyxtime). + 2005-07-04 Jürgen Spitzmüller * ControlToc.[Ch]: new method getGuiName, which is used by the frontends diff --git a/src/frontends/controllers/ControlChanges.C b/src/frontends/controllers/ControlChanges.C index d2005a9638..ea6b8909cf 100644 --- a/src/frontends/controllers/ControlChanges.C +++ b/src/frontends/controllers/ControlChanges.C @@ -19,14 +19,12 @@ #include "changes.h" #include "funcrequest.h" #include "lyxfind.h" -#include "support/lstrings.h" +#include "support/lyxtime.h" using std::string; namespace lyx { -using support::rtrim; - namespace frontend { @@ -47,9 +45,7 @@ string const ControlChanges::getChangeDate() if (c.type == Change::UNCHANGED || !c.changetime) return string(); - // ctime adds newline; trim it off! - string const date = rtrim(ctime(&c.changetime), "\n"); - return date; + return formatted_time(c.changetime); } diff --git a/src/support/ChangeLog b/src/support/ChangeLog index c0f5aeac35..25f25ef37c 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,8 @@ +2005-07-05 Jürgen Spitzmüller + + * lyxtime.[Ch]: two new functions formatted_time, which return + the strftime-formatted localized date/time. + 2005-06-24 Georg Baum * FileName.C (mangledFilename): replace spaces with _ diff --git a/src/support/lyxtime.C b/src/support/lyxtime.C index cbe6223bbb..aabd1229da 100644 --- a/src/support/lyxtime.C +++ b/src/support/lyxtime.C @@ -11,6 +11,9 @@ #include #include "support/lyxtime.h" +#include "lyxrc.h" + +using std::string; namespace lyx { @@ -19,4 +22,19 @@ time_type current_time() return time(0); } + +string const formatted_time(time_type t, string const & fmt) +{ + struct tm * loc_tm = localtime(&t); + char date[50]; + strftime(date, sizeof(date), fmt.c_str(), loc_tm); + return string(date); +} + + +string const formatted_time(time_type t) +{ + return formatted_time(t, lyxrc.date_insert_format); +} + } // namespace lyx diff --git a/src/support/lyxtime.h b/src/support/lyxtime.h index c58c9ab281..71d62fcee9 100644 --- a/src/support/lyxtime.h +++ b/src/support/lyxtime.h @@ -5,6 +5,7 @@ * Licence details can be found in the file COPYING. * * \author John Levon + * \author Jürgen Spitzmüller * * Full author contact details are available in file CREDITS. */ @@ -13,6 +14,8 @@ #define LYXTIME_H #include +#include + namespace lyx { @@ -20,6 +23,18 @@ typedef time_t time_type; time_type current_time(); +/** Returns a locale-dependent formatting of the date + *  and time encoded in \c time. The \p fmt string + * holds the formatting arguments of \c strftime. + */ +std::string const formatted_time(time_type t, std::string const & fmt); + +/** Returns a locale-dependent formatting of the date + *  and time encoded in \c time. For the formatting, + * \c lyxrc.date_insert_format is being used. + */ +std::string const formatted_time(time_type t); + }; // namespace lyx #endif // LYXTIME_H diff --git a/src/text3.C b/src/text3.C index 4f99c9cee6..b8dfda9675 100644 --- a/src/text3.C +++ b/src/text3.C @@ -57,6 +57,7 @@ #include "support/lstrings.h" #include "support/lyxlib.h" #include "support/convert.h" +#include "support/lyxtime.h" #include "mathed/math_hullinset.h" #include "mathed/math_macrotemplate.h" @@ -954,27 +955,14 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) break; } - case LFUN_DATE_INSERT: { - lyx::cap::replaceSelection(cur); - time_t now_time_t = time(NULL); - struct tm * now_tm = localtime(&now_time_t); - setlocale(LC_TIME, ""); - string arg; - if (!cmd.argument.empty()) - arg = cmd.argument; + case LFUN_DATE_INSERT: + if (cmd.argument.empty()) + bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, + lyx::formatted_time(lyx::current_time()))); else - arg = lyxrc.date_insert_format; - char datetmp[32]; - int const datetmp_len = - ::strftime(datetmp, 32, arg.c_str(), now_tm); - - for (int i = 0; i < datetmp_len; i++) - insertChar(cur, datetmp[i]); - - cur.resetAnchor(); - moveCursor(cur, false); + bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, + lyx::formatted_time(lyx::current_time(), cmd.argument))); break; - } case LFUN_MOUSE_TRIPLE: if (cmd.button() == mouse_button::button1) { -- 2.39.2