Patchwork Add support for english date names on non-english systems

login
register
mail settings
Submitter A. Klitzing
Date Feb. 24, 2015, 1:22 p.m.
Message ID <CAJaftdhr6X_iZU53UKN9Eae1fDG14cUrCUriukja9vqLsyCgiQ@mail.gmail.com>
Download mbox | patch
Permalink /patch/7826/
State Accepted
Headers show

Comments

A. Klitzing - Feb. 24, 2015, 1:22 p.m.
Hi there!

We have here a jenkins with build jobs on different slaves that will do
some operations with "dates" parameter. Some systems uses English locale
and some systems uses German locale. So we needed to configure the job to
uses other date names.

As this is really annoying to keep the systems locale in mind for some
operations I looked into util.py. It would be helpful for automated systems
if the "default English" date names would even usable on other locales.

I attached a simple patch for this.

Best regards
  André Klitzing
Yuya Nishihara - Feb. 24, 2015, 3:26 p.m.
On Tue, 24 Feb 2015 14:22:20 +0100, A. Klitzing wrote:
> We have here a jenkins with build jobs on different slaves that will do
> some operations with "dates" parameter. Some systems uses English locale
> and some systems uses German locale. So we needed to configure the job to
> uses other date names.
> 
> As this is really annoying to keep the systems locale in mind for some
> operations I looked into util.py. It would be helpful for automated systems
> if the "default English" date names would even usable on other locales.
> 
> I attached a simple patch for this.

You should include these in commit messages.

http://mercurial.selenic.com/wiki/ContributingChanges

> # HG changeset patch
> # User André Klitzing <aklitzing@gmail.com>
> # Date 1424783533 -3600
> #      Tue Feb 24 14:12:13 2015 +0100
> # Node ID 090f886be9c7b29b39d48afbe6c612f0914dff0c
> # Parent  ff5caa8dfd993680d9602ca6ebb14da9de10d5f4
> util: accept "now, today, yesterday" for dates even the locale is not english
> 
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -1350,11 +1350,11 @@
>          formats = defaultdateformats
>      date = date.strip()
>  
> -    if date == _('now'):
> +    if date == 'now' or date == _('now'):
>          return makedate()
> -    if date == _('today'):
> +    if date == 'today' or date == _('today'):
>          date = datetime.date.today().strftime('%b %d')
> -    elif date == _('yesterday'):
> +    elif date == 'yesterday' or date == _('yesterday'):
>          date = (datetime.date.today() -
>                  datetime.timedelta(days=1)).strftime('%b %d')

I like this and I found it works out of the box for LANG=ja probably because
foozy doesn't translate these words purposely.

Regards,

Patch

# HG changeset patch
# User André Klitzing <aklitzing@gmail.com>
# Date 1424783533 -3600
#      Tue Feb 24 14:12:13 2015 +0100
# Node ID 090f886be9c7b29b39d48afbe6c612f0914dff0c
# Parent  ff5caa8dfd993680d9602ca6ebb14da9de10d5f4
util: accept "now, today, yesterday" for dates even the locale is not english

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1350,11 +1350,11 @@ 
         formats = defaultdateformats
     date = date.strip()
 
-    if date == _('now'):
+    if date == 'now' or date == _('now'):
         return makedate()
-    if date == _('today'):
+    if date == 'today' or date == _('today'):
         date = datetime.date.today().strftime('%b %d')
-    elif date == _('yesterday'):
+    elif date == 'yesterday' or date == _('yesterday'):
         date = (datetime.date.today() -
                 datetime.timedelta(days=1)).strftime('%b %d')