]> git.lyx.org Git - lyx.git/commitdiff
localize date/time
authorJürgen Spitzmüller <spitz@lyx.org>
Tue, 5 Jul 2005 09:01:52 +0000 (09:01 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Tue, 5 Jul 2005 09:01:52 +0000 (09:01 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10129 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlChanges.C
src/support/ChangeLog
src/support/lyxtime.C
src/support/lyxtime.h
src/text3.C

index eb6a546816b9cfbb3c0f66d4e064a5417179fffa..e808f38fdb0d8276cf216dd0cacc92656e355ac1 100644 (file)
@@ -1,3 +1,8 @@
+2005-07-05  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
+
+       * text3.C (doDispatch): rewrite LFUN_DATE_INSERT using the brandnew
+       formatted_time methods in support/lyxtime.
+
 2005-07-04  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * toc.[Ch]: new method getGuiName, which is used by the frontends 
index aa550a47492a0222c4dfaf6664d7139bcd1ee276..204eeebf872143aad031a4a395ac0ecc805b1030 100644 (file)
@@ -1,3 +1,8 @@
+2005-07-05  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
+
+       * ControlChanges.C (getChangeDate): use localized date (from 
+       support/lyxtime).
+
 2005-07-04  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * ControlToc.[Ch]: new method getGuiName, which is used by the frontends 
index d2005a9638135f623d75a9542aebe82225c81686..ea6b8909cf621543a8136023dded6da3a4136c78 100644 (file)
 #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);
 }
 
 
index c0f5aeac35c23a344bf6038e83fbb409f98393f9..25f25ef37c15e5cf189e69b05bb655a79f34152d 100644 (file)
@@ -1,3 +1,8 @@
+2005-07-05  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
+
+       * lyxtime.[Ch]: two new functions formatted_time, which return
+       the strftime-formatted localized date/time.
+
 2005-06-24  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
 
        * FileName.C (mangledFilename): replace spaces with _
index cbe6223bbb26b412a873c537a52e05f3319a922d..aabd1229dab1a7cbfb82b93d23d71342619f8f16 100644 (file)
@@ -11,6 +11,9 @@
 #include <config.h>
 
 #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
index c58c9ab2818b499c119be36d29ad4cc9dad810fe..71d62fcee94b46921529e663a764ee9536e3681d 100644 (file)
@@ -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 <time.h>
+#include <string>
+
 
 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
index 4f99c9cee6a8d0474ce337d147ccd254ab85647e..b8dfda96754a62403fda7b749660f28370d1cad0 100644 (file)
@@ -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) {