* Bug 15200 fixed & weekday() upgraded (SEP) 26/19326/13
Samuel GOUGEON [Sat, 8 Jul 2017 00:47:50 +0000 (02:47 +0200)]
  - http://bugzilla.scilab.org/15200
  - SEP: https://wiki.scilab.org/SEP/2017%20-%20weekday()%20uppgrade
  - ML http://mailinglists.scilab.org/Scilab-users-SEP-upgrading-weekday-tt4036719.html
    New proposed page in PDF posted on the ML

Change-Id: I66335f03e49e49f347436067f554d8d7354fdae5

scilab/CHANGES.md
scilab/modules/time/help/en_US/weekday.xml
scilab/modules/time/help/fr_FR/weekday.xml
scilab/modules/time/help/ja_JP/weekday.xml [deleted file]
scilab/modules/time/help/ru_RU/weekday.xml [new file with mode: 0644]
scilab/modules/time/macros/weekday.sci
scilab/modules/time/tests/unit_tests/weekday.tst [new file with mode: 0644]

index 87bdffb..e76d649 100644 (file)
@@ -160,13 +160,16 @@ Feature changes and additions
 * `plot` can now work in semi or bi-logarithmic mode with some input logflag.
 * `plotimplicit()` function added.
 * The default smarter grid_style value is now 7 instead of 3.
+* `weekday` accepts new date formats and syntaxes like `weekday()`, `weekday([2017 7 15])`, `weekday(2017, 7, 15)`, `weekday("15/7/2017")`,  `weekday("15-Jul-2017")`,  `weekday("2017-07-15")`, and `weekday("2017-07-15 21:53:17")`. A language option applying to the day names is now available.
 
 Help pages:
 -----------
 
 * overhauled / rewritten: `bitget`, `edit`, `factorial`
 * fixed / improved:  `bench_run` `M_SWITCH`, `comet`, `comet3d`
-
+* Rewritten: `weekday`
+* Translations added:
+  - (ru): `weekday`
 
 User Interface improvements:
 ----------------------------
@@ -229,7 +232,6 @@ Bug Fixes
 ---------
 
 ### Bugs fixed in 6.1.0:
-<<<<<<< HEAD
 * [#2694](https://bugzilla.scilab.org/2694): `bitget` did not accept positive integers of types int8, int16 or int32.
 * [#6070](https://bugzilla.scilab.org/6070): How to make multiscaled plots was not documented.
 * [#7562](https://bugzilla.scilab.org/7562): `factorial` could use a huge memory amount even for a scalar argument.
@@ -285,6 +287,7 @@ Bug Fixes
 * [#14985](https://bugzilla.scilab.org/14985): Scilab crashed if a .bin file was not found.
 * [#15068](https://bugzilla.scilab.org/15068): `size(sum(ones(2,3,4,5),4))` was [4 2 3] instead of [2 3 4].
 * [#15087](https://bugzilla.scilab.org/15087): Deleting rows or columns from a matrix is slow (regression)
+* [#15200](https://bugzilla.scilab.org/15200): `weekday` yielded an error for some row of input dates.
 * [#15248](https://bugzilla.scilab.org/15248): `lsq`was leaking memory.
 * [#15269](https://bugzilla.scilab.org/15269): `xgetech` was poor and stiff compared to any combination of `gca()` properties `.axes_bounds`, `.data_bounds`, `.log_flags`, and `.margins`. It is removed.
 * [#15271](https://bugzilla.scilab.org/15271): `bitget` needed to be upgraded.
index bcf66c7..67d8744 100644 (file)
@@ -2,8 +2,8 @@
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) INRIA -
- *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2017 - Samuel GOUGEON
  *
  * This file is hereby licensed under the terms of the GNU GPL v2.0,
  * pursuant to article 5.3.4 of the CeCILL v.2.1.
  * along with this program.
  *
  -->
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="en" xml:id="weekday">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+        xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
+        xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="en"
+        xml:id="weekday">
     <refnamediv>
         <refname>weekday</refname>
-        <refpurpose>Return day of week</refpurpose>
+        <refpurpose>Day's index and name in its week for given dates</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Syntax</title>
-        <synopsis>[N,S] = weekday(D)
-            [N,S] = weekday(D, form)
+        <synopsis>
+            [I, Names] = weekday()
+            [I, Names] = weekday(N)
+            [I, Names] = weekday(YMD)
+            [I, Names] = weekday(Y, M, D)
+            [I, Names] = weekday(dateStrings)
+            [I, Names] = weekday(.., "long")
+            [I, Names] = weekday(.., la_NG)
         </synopsis>
     </refsynopsisdiv>
+    <refsection role="arguments">
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>N</term>
+                <listitem>
+                    <para>
+                    Array of decimal date numbers as returned by <literal>datenum(..)</literal>.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>YMD</term>
+                <listitem>
+                    <para>
+                    Matrix of decimal integers with n rows and 3 columns. Each row defines a date:
+                    Year numbers are in column <literal>YMD(:,1)</literal>.
+                    Month indices in [1,12] are in column <literal>YMD(:,2)</literal>.
+                    Day indices in [1,31] are in column <literal>YMD(:,3)</literal>.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>Y, M, D</term>
+                <listitem>
+                    <para>
+                    3 element-wise arrays of decimal integers with the same sizes. The date #i is
+                    defined by <literal>D(i)/M(i)/Y(i)</literal>.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>dateStrings</term>
+                <listitem>
+                    <para>
+                    Array of strings specifying dates according to 5 possible formats described
+                    here-below. In the array, all the dates must follow the same format:
+                    <itemizedlist>
+                        <listitem>
+                            <literal>"YYYY-MM-DD"</literal> : <literal>DD &lt; 10</literal> or/and
+                            <literal>MM &lt; 10</literal> must have a leading zero. Example:
+                            <literal>"2017-09-07"</literal>.
+                        </listitem>
+                        <listitem>
+                            <literal>"YYYY-MM-DD HH:MN:SS.ss"</literal> or
+                            <literal>"YYYY-MM-DD whatever you want"</literal> : same as above. Only
+                            the part before the first space is considered.
+                        </listitem>
+                        <listitem>
+                            <literal>"D/M/Y"</literal> : Days <literal>D &lt; 10</literal> or/and
+                            Months <literal>M &lt; 10</literal> may or not have a leading zero.
+                            Example: <literal>"7/09/2017"</literal>.
+                        </listitem>
+                        <listitem>
+                            <literal>"enD/M/Y"</literal> : Same as above, with the prefix "en" (for
+                            "english") and M/D instead of D/M. Example: <literal>"en7/24/2017"</literal>.
+                        </listitem>
+                        <listitem>
+                            <literal>"D-Mmm-YYYY"</literal> where <literal>Mmm</literal> is the
+                            short name of the Month in english: <literal>Jan, Feb, Mar, Apr, May,
+                                Jun, Jul, Aug, Sep, Oct, Nov, Dec</literal>. Days
+                            <literal>D &lt; 10</literal> may or not have a leading zero.
+                        </listitem>
+                    </itemizedlist>
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>"long"</term>
+                <listitem>
+                    <para>
+                    Optional keyword to get days names in long full form: "Wednesday" instead of
+                    "Wed", etc. Can be used anywhere after the Days input argument(s).
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>la_NG</term>
+                <listitem>
+                    <para>
+                    Optional keyword = unique string specifying the language in which days names
+                    are requested, in the standard format like "en_US", "fr_FR", etc. Can be used
+                    anywhere after the Days input argument(s).
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>I</term>
+                <listitem>
+                    <para>
+                    Array of decimal integers in [1,7], having the sizes of <varname>N</varname>,
+                    <varname>YMD(:,1)</varname>, <varname>Y, M and D</varname>, or
+                    <literal>dateStrings</literal>: 1 is for Sunday, 2 for Monday, .., 7 for Saturday.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>Names</term>
+                <listitem>
+                <para>
+                    Array of text words having <varname>I</varname> sizes: Names of days in their
+                    weeks, for the given dates. Names are returned in short form like "Wed" standing
+                    for "Wednesday", unless the <varname>"long"</varname> option is used.
+                </para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
     <refsection>
         <title>Description</title>
-        <para>[N,S] = weekday(D) returns the day of the week in numeric(N) and string(S) form for a given serial date number or date string D. Input argument D can represent more than one date in an array of serial date number.</para>
-        <para>[N,S] = weekday(D, form) returns the week in numeric(N) and string(S) form, where the content of S depends on the form argument. If form is 'long', then S contains the full name of the weekday (e.g, Tuesday). If form is 'short', then S contains an abbreviated name (e.g., Tue) from this table.</para>
+        <para>
+            For each given dates, or by default for today, <function>weekday</function> computes and
+            returns the integer index of the day in its week, from 1 to 7. The abbreviated or full
+            name of the day may also be returned, in the Scilab session language. If a language code
+            is provided and targets a language supported in Scilab, the day name is translated into
+            the language before being returned.
+        </para>
+        <para>
+            <table border="1">
+                <tr><th>Lang</th><th>i</th><th>short</th><th>long</th><td>.......</td><th>Lang</th><th>i</th><th>short</th><th>long</th></tr>
+                <tr><td>en_US</td><td>1</td><td>Sun</td><td>Sunday</td><td>    </td><td>pt_BR</td><td>1</td><td>Dom</td><td>Domingo</td></tr>
+                <tr><td>en_US</td><td>2</td><td>Mon</td><td>Monday</td><td>    </td><td>pt_BR</td><td>2</td><td>Seg</td><td>Segunda-feira</td></tr>
+                <tr><td>en_US</td><td>3</td><td>Tue</td><td>Tuesday</td><td>    </td><td>pt_BR</td><td>3</td><td>Ter</td><td>Terça-feira</td></tr>
+                <tr><td>en_US</td><td>4</td><td>Wed</td><td>Wednesday</td><td>    </td><td>pt_BR</td><td>4</td><td>Qua</td><td>Quarta-feira</td></tr>
+                <tr><td>en_US</td><td>5</td><td>Thu</td><td>Thursday</td><td>    </td><td>pt_BR</td><td>5</td><td>Qui</td><td>Quinta-feira</td></tr>
+                <tr><td>en_US</td><td>6</td><td>Fri</td><td>Friday</td><td>    </td><td>pt_BR</td><td>6</td><td>Sex</td><td>Sexta-feira</td></tr>
+                <tr><td>en_US</td><td>7</td><td>Sat</td><td>Saturday</td><td>    </td><td>pt_BR</td><td>7</td><td>Sáb</td><td>Sábado</td></tr>
+                <tr><td>fr_FR</td><td>1</td><td>Dim.</td><td>Dimanche</td><td>    </td><td>ru_RU</td><td>1</td><td>Вск</td><td>Воскресенье</td></tr>
+                <tr><td>fr_FR</td><td>2</td><td>Lun.</td><td>Lundi</td><td>    </td><td>ru_RU</td><td>2</td><td>Пнд</td><td>Понедельник</td></tr>
+                <tr><td>fr_FR</td><td>3</td><td>Mar.</td><td>Mardi</td><td>    </td><td>ru_RU</td><td>3</td><td>Втр</td><td>Вторник</td></tr>
+                <tr><td>fr_FR</td><td>4</td><td>Mer.</td><td>Mercredi</td><td>    </td><td>ru_RU</td><td>4</td><td>Срд</td><td>Среда</td></tr>
+                <tr><td>fr_FR</td><td>5</td><td>Jeu.</td><td>Jeudi</td><td>    </td><td>ru_RU</td><td>5</td><td>Чтв</td><td>Четверг</td></tr>
+                <tr><td>fr_FR</td><td>6</td><td>Ven.</td><td>Vendredi</td><td>    </td><td>ru_RU</td><td>6</td><td>Птн</td><td>Пятница</td></tr>
+                <tr><td>fr_FR</td><td>7</td><td>Sam.</td><td>Samedi</td><td>    </td><td>ru_RU</td><td>7</td><td>Сбт</td><td>Суббота</td></tr>
+                <tr><td>ja_JP</td><td>1</td><td>日</td><td>日曜日</td><td>    </td><td>zh_CN</td><td>1</td><td>星期日</td><td>星期日</td></tr>
+                <tr><td>ja_JP</td><td>2</td><td>月</td><td>月曜日</td><td>    </td><td>zh_CN</td><td>2</td><td>星期一</td><td>星期一</td></tr>
+                <tr><td>ja_JP</td><td>3</td><td>火</td><td>火曜日</td><td>    </td><td>zh_CN</td><td>3</td><td>星期二</td><td>星期二</td></tr>
+                <tr><td>ja_JP</td><td>4</td><td>水</td><td>水曜日</td><td>    </td><td>zh_CN</td><td>4</td><td>星期三</td><td>星期三</td></tr>
+                <tr><td>ja_JP</td><td>5</td><td>木</td><td>木曜日</td><td>    </td><td>zh_CN</td><td>5</td><td>星期四</td><td>星期四</td></tr>
+                <tr><td>ja_JP</td><td>6</td><td>金</td><td>金曜日</td><td>    </td><td>zh_CN</td><td>6</td><td>星期五</td><td>星期五</td></tr>
+                <tr><td>ja_JP</td><td>7</td><td>土</td><td>土曜日</td><td>    </td><td>zh_CN</td><td>7</td><td>星期六</td><td>星期六</td></tr>
+            </table>
+        </para>
     </refsection>
     <refsection>
         <title>Examples</title>
-        <programlisting role="example"><![CDATA[
-today = datenum();
-[N,S] = weekday(today)
-[N,S] = weekday(today,'short')
-[N,S] = weekday(today,'long')
- ]]></programlisting>
+        <programlisting role="example">
+            <![CDATA[
+// Today
+[i, n] = weekday()
+[i, n] = weekday("long"); n
+[i, n] = weekday("long","ru_RU"); n
+
+// Explicit input dates
+[I, N] = weekday(     ["01/1/1970" "11/09/2001" "26/12/2004"])
+[I, N] = weekday("en"+["1/01/1970" "09/11/2001" "12/26/2004"])
+[I, N] = weekday(["1/1/1970" "11/9/2001" "26/12/2004"], "long"); N
+[I, N] = weekday(["1970-01-01" "2001-09-11" "2004-12-26"], "long"); N
+[I, N] = weekday(["1970-01-01 00:00:00" "2001-09-11 08:14:00" "2004-12-26 00:58:53"], "long"); N
+[I, N] = weekday(["1-Jan-1970" "11-Sep-2001" "26-Dec-2004"], "long"); N
+[I, N] = weekday(["1970-01-01" "en12/26/2004"]);   // => error: all dates must have the same format
+[I, N] = weekday([1970 1 1 ; 2001 9 11 ; 2004 12 26], "long"); N
+[I, N] = weekday([1970 2001 2004], [1 9 12], [1 11 26], "long"); N
+D = datenum([1970 1 1 ; 2001 9 11 ; 2004 12 26])
+[I, N] = weekday(D, "long"); N
+
+// Language option
+[I, N] = weekday(["1/1/1970" "11/9/2001" "26/12/2004"], "zh_CN"); N
+[I, N] = weekday(["1/1/1970" "11/9/2001" "26/12/2004"], "fr_FR", "long"); N
+ ]]>
+        </programlisting>
     </refsection>
     <refsection role="see also">
         <title>See also</title>
         <simplelist type="inline">
             <member>
-                <link linkend="datenum">datenum</link>
+                <link linkend="eomday">eomday</link>
             </member>
             <member>
-                <link linkend="datevec">datevec</link>
+                <link linkend="datenum">datenum</link>
             </member>
             <member>
-                <link linkend="weekday">weekday</link>
+                <link linkend="datevec">datevec</link>
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    <itemizedlist>
+                        <listitem>
+                            New syntaxes added: <literal>weekday()</literal>,
+                            <literal>weekday(YMD)</literal>,
+                            <literal>weekday(Y, M, D)</literal>,
+                            <literal>weekday(dateStrings)</literal>.
+                        </listitem>
+                        <listitem>
+                            Language option added.
+                        </listitem>
+                        <listitem>
+                            Algorithm now based on <literal>datenum()</literal> (5 formats).
+                        </listitem>
+                    </itemizedlist>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 7f2be26..8d26493 100644 (file)
@@ -2,8 +2,8 @@
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) INRIA -
- *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2017 - Samuel GOUGEON
  *
  * This file is hereby licensed under the terms of the GNU GPL v2.0,
  * pursuant to article 5.3.4 of the CeCILL v.2.1.
  * along with this program.
  *
  -->
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="fr" xml:id="weekday">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+        xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
+        xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="fr"
+        xml:id="weekday">
     <refnamediv>
         <refname>weekday</refname>
-        <refpurpose>Retourne le jour de la semaine</refpurpose>
+        <refpurpose>Numéro et nom du jour de la semaine pour des dates données</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
-        <title>Séquence d'appel</title>
-        <synopsis>[N,S] = weekday(D)
-            [N,S] = weekday(D, form)
+        <title>Syntaxe</title>
+        <synopsis>
+            [I, Names] = weekday()
+            [I, Names] = weekday(N)
+            [I, Names] = weekday(YMD)
+            [I, Names] = weekday(Y, M, D)
+            [I, Names] = weekday(dateStrings)
+            [I, Names] = weekday(.., "long")
+            [I, Names] = weekday(.., la_NG)
         </synopsis>
     </refsynopsisdiv>
+    <refsection role="arguments">
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>N</term>
+                <listitem>
+                    <para>
+                    Tableau de dates numériques décimales telles que fournies par <literal>datenum(..)</literal>.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>YMD</term>
+                <listitem>
+                    <para>
+                    Matrice d'entiers décimaux à n lignes et 3 colonnes. Chaque ligne définit une date :
+                    le millesime des années figure en colonne <literal>YMD(:,1)</literal>.
+                    Le numéro 1 à 12 des mois dans l'année figure en colonne <literal>YMD(:,2)</literal>.
+                    Le numéro 1 à 31 des jours dans le mois figure en colonne <literal>YMD(:,3)</literal>.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>Y, M, D</term>
+                <listitem>
+                    <para>
+                    3 tableaux d'entiers décimaux de mêmes tailles. La date n°i est définie par
+                    <literal>D(i)/M(i)/Y(i)</literal>.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>dateStrings</term>
+                <listitem>
+                    <para>
+                    Tableau de textes spécifiant des dates selon 5 formats possibles décrits ci-dessous.
+                    Toutes les dates fournies doivent avoir le même format :
+                    <itemizedlist>
+                        <listitem>
+                            <literal>"YYYY-MM-DD"</literal> : <literal>DD &lt; 10</literal> ou/et
+                            <literal>MM &lt; 10</literal> doivent inclure un zéro initial. Exemple:
+                            <literal>"2017-09-07"</literal>.
+                        </listitem>
+                        <listitem>
+                            <literal>"YYYY-MM-DD HH:MN:SS.ss"</literal> ou
+                            <literal>"YYYY-MM-DD ce que vous voulez"</literal> : comme ci-avant.
+                            Seule la partie avant le 1er espace est considérée.
+                        </listitem>
+                        <listitem>
+                            <literal>"D/M/Y"</literal> : les jours <literal>D &lt; 10</literal> ou/et
+                            les Mois <literal>M &lt; 10</literal> peuvent ou non inclure un zéro
+                            initial. Exemple: <literal>"7/09/2017"</literal>.
+                        </listitem>
+                        <listitem>
+                            <literal>"enD/M/Y"</literal> : comme ci-dessus, avec le préfixe "en"
+                            (pour "english") et M/D au lieu de D/M. Exemple: <literal>"en7/24/2017"</literal>.
+                        </listitem>
+                        <listitem>
+                            <literal>"D-Mmm-YYYY"</literal> où <literal>Mmm</literal> désigne le nom
+                            court du mois en anglais : <literal>Jan, Feb, Mar, Apr, May,
+                                Jun, Jul, Aug, Sep, Oct, Nov, Dec</literal>. Les jours
+                            <literal>D &lt; 10</literal> peuvent ou non inclure un zéro initial.
+                        </listitem>
+                    </itemizedlist>
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>"long"</term>
+                <listitem>
+                    <para>
+                    Mot-clé optionnel à utiliser pour retourner le nom des jours en format long :
+                    "Wednesday" au lieu de "Wed", "Dimanche" au lieu de "Dim.", etc. Peut être
+                    utilisé n'importe où <emphasis role="italic">après</emphasis> les arguments
+                    spécifiant les dates.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>la_NG</term>
+                <listitem>
+                    <para>
+                    Option linguistique = mot texte unique indiquant la langue dan laquelle le nom
+                    des jours des dates spécifiées doit être retourné, en format standard. Exemple :
+                    "en_US", "fr_FR", etc. Peut être utilisé n'importe où
+                    <emphasis role="italic">après</emphasis> les arguments spécifiant les dates.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>I</term>
+                <listitem>
+                    <para>
+                    Tableau d'entiers décimaux de 1 à 7, de la taille des tableaux <varname>N</varname>,
+                    <varname>YMD(:,1)</varname>, <varname>Y, M et D</varname>, ou
+                    <literal>dateStrings</literal> : le numéro 1 correspond à dimanche, 2 à lundi, etc.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>Names</term>
+                <listitem>
+                <para>
+                    Tableau de mots texte de la taille de <varname>I</varname> : noms explicites des
+                    jours de la semaine, pour les dates indiquées. Le format court (""Dim." au lieu
+                    de "Dimanche", etc) est utilisé, à moins que l'option <varname>"long"</varname>
+                    soit spécifiée.
+                </para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
     <refsection>
         <title>Description</title>
         <para>
-            [N,S] = weekday(D) retourne le jour de la semaine sous une forme numérique(N) et une chaîne de caractère(S) pour une date donnée (sous la forme d'un "serial date number" : see <link linkend="datenum">datenum</link>). Le paramètre passé en entrée peut être une matrice de "serial date number"
+            Pour chaque date donnée, ou par défaut pour la date courante d'aujourd'hui,
+            <function>weekday</function> calcule et retourne le numéro entier de 1 à 7  du jour
+            dans la semaine. Le nom abbrégé ou complet du jour de la semaine peut aussi être retourné,
+            par défaut dans la langue de la session Scilab. Si un code linguistique du type "en_US"
+            est utilisé et correspond à une langue supportée par Scilab, le nom du jour est retourné
+            dans la langue choisie.
+        </para>
+        <para>
+            <table border="1">
+                <tr><th>Lang</th><th>i</th><th>short</th><th>long</th><td>.......</td><th>Lang</th><th>i</th><th>short</th><th>long</th></tr>
+                <tr><td>en_US</td><td>1</td><td>Sun</td><td>Sunday</td><td>    </td><td>pt_BR</td><td>1</td><td>Dom</td><td>Domingo</td></tr>
+                <tr><td>en_US</td><td>2</td><td>Mon</td><td>Monday</td><td>    </td><td>pt_BR</td><td>2</td><td>Seg</td><td>Segunda-feira</td></tr>
+                <tr><td>en_US</td><td>3</td><td>Tue</td><td>Tuesday</td><td>    </td><td>pt_BR</td><td>3</td><td>Ter</td><td>Terça-feira</td></tr>
+                <tr><td>en_US</td><td>4</td><td>Wed</td><td>Wednesday</td><td>    </td><td>pt_BR</td><td>4</td><td>Qua</td><td>Quarta-feira</td></tr>
+                <tr><td>en_US</td><td>5</td><td>Thu</td><td>Thursday</td><td>    </td><td>pt_BR</td><td>5</td><td>Qui</td><td>Quinta-feira</td></tr>
+                <tr><td>en_US</td><td>6</td><td>Fri</td><td>Friday</td><td>    </td><td>pt_BR</td><td>6</td><td>Sex</td><td>Sexta-feira</td></tr>
+                <tr><td>en_US</td><td>7</td><td>Sat</td><td>Saturday</td><td>    </td><td>pt_BR</td><td>7</td><td>Sáb</td><td>Sábado</td></tr>
+                <tr><td>fr_FR</td><td>1</td><td>Dim.</td><td>Dimanche</td><td>    </td><td>ru_RU</td><td>1</td><td>Вск</td><td>Воскресенье</td></tr>
+                <tr><td>fr_FR</td><td>2</td><td>Lun.</td><td>Lundi</td><td>    </td><td>ru_RU</td><td>2</td><td>Пнд</td><td>Понедельник</td></tr>
+                <tr><td>fr_FR</td><td>3</td><td>Mar.</td><td>Mardi</td><td>    </td><td>ru_RU</td><td>3</td><td>Втр</td><td>Вторник</td></tr>
+                <tr><td>fr_FR</td><td>4</td><td>Mer.</td><td>Mercredi</td><td>    </td><td>ru_RU</td><td>4</td><td>Срд</td><td>Среда</td></tr>
+                <tr><td>fr_FR</td><td>5</td><td>Jeu.</td><td>Jeudi</td><td>    </td><td>ru_RU</td><td>5</td><td>Чтв</td><td>Четверг</td></tr>
+                <tr><td>fr_FR</td><td>6</td><td>Ven.</td><td>Vendredi</td><td>    </td><td>ru_RU</td><td>6</td><td>Птн</td><td>Пятница</td></tr>
+                <tr><td>fr_FR</td><td>7</td><td>Sam.</td><td>Samedi</td><td>    </td><td>ru_RU</td><td>7</td><td>Сбт</td><td>Суббота</td></tr>
+                <tr><td>ja_JP</td><td>1</td><td>日</td><td>日曜日</td><td>    </td><td>zh_CN</td><td>1</td><td>星期日</td><td>星期日</td></tr>
+                <tr><td>ja_JP</td><td>2</td><td>月</td><td>月曜日</td><td>    </td><td>zh_CN</td><td>2</td><td>星期一</td><td>星期一</td></tr>
+                <tr><td>ja_JP</td><td>3</td><td>火</td><td>火曜日</td><td>    </td><td>zh_CN</td><td>3</td><td>星期二</td><td>星期二</td></tr>
+                <tr><td>ja_JP</td><td>4</td><td>水</td><td>水曜日</td><td>    </td><td>zh_CN</td><td>4</td><td>星期三</td><td>星期三</td></tr>
+                <tr><td>ja_JP</td><td>5</td><td>木</td><td>木曜日</td><td>    </td><td>zh_CN</td><td>5</td><td>星期四</td><td>星期四</td></tr>
+                <tr><td>ja_JP</td><td>6</td><td>金</td><td>金曜日</td><td>    </td><td>zh_CN</td><td>6</td><td>星期五</td><td>星期五</td></tr>
+                <tr><td>ja_JP</td><td>7</td><td>土</td><td>土曜日</td><td>    </td><td>zh_CN</td><td>7</td><td>星期六</td><td>星期六</td></tr>
+            </table>
         </para>
-        <para>[N,S] = weekday(D, form)) retourne le jour de la semaine sous une forme numérique(N) et une chaîne de caractère(S), où le contenu de S dépend du paramètre "form". Si form est égal à 'long', S contient le nom complet du jour de la semaine tandis que si form est égal à 'short', S contient l'abbreviation du nom du jour de la semaine.</para>
     </refsection>
     <refsection>
         <title>Exemples</title>
-        <programlisting role="example"><![CDATA[
-today = datenum();
-[N,S] = weekday(today)
-[N,S] = weekday(today,'short')
-[N,S] = weekday(today,'long')
- ]]></programlisting>
+        <programlisting role="example">
+            <![CDATA[
+// Aujourd'hui
+[i, n] = weekday()
+[i, n] = weekday("long"); n
+[i, n] = weekday("long","ru_RU"); n
+
+// Dates explicitement indiquées selon différents formats :
+[I, N] = weekday(     ["01/1/1970" "11/09/2001" "26/12/2004"])
+[I, N] = weekday("en"+["1/01/1970" "09/11/2001" "12/26/2004"])
+[I, N] = weekday(["1970-01-01" "2001-09-11" "2004-12-26"], "long"); N
+[I, N] = weekday(["1970-01-01 00:00:00" "2001-09-11 08:14:00" "2004-12-26 00:58:53"], "long"); N
+[I, N] = weekday(["1-Jan-1970" "11-Sep-2001" "26-Dec-2004"], "long"); N
+[I, N] = weekday(["1970-01-01" "en12/26/2004"]);   // => erreur : même format de dates attendu
+[I, N] = weekday([1970 1 1 ; 2001 9 11 ; 2004 12 26], "long"); N
+[I, N] = weekday([1970 2001 2004], [1 9 12], [1 11 26], "long"); N
+D = datenum([1970 1 1 ; 2001 9 11 ; 2004 12 26])
+[I, N] = weekday(D, "long"); N
+
+// Option lang
+[I, N] = weekday(["1/1/1970" "11/9/2001" "26/12/2004"], "zh_CN"); N
+[I, N] = weekday(["1/1/1970" "11/9/2001" "26/12/2004"], "fr_FR", "long"); N
+ ]]>
+        </programlisting>
     </refsection>
     <refsection role="see also">
         <title>Voir aussi</title>
         <simplelist type="inline">
             <member>
-                <link linkend="datenum">datenum</link>
+                <link linkend="eomday">eomday</link>
             </member>
             <member>
-                <link linkend="datevec">datevec</link>
+                <link linkend="datenum">datenum</link>
             </member>
             <member>
-                <link linkend="weekday">weekday</link>
+                <link linkend="datevec">datevec</link>
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>Historique</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    <itemizedlist>
+                        <listitem>
+                            Nouvelles syntaxes ajoutées : <literal>weekday()</literal>,
+                            <literal>weekday(YMD)</literal>,
+                            <literal>weekday(Y, M, D)</literal>,
+                            <literal>weekday(dateStrings)</literal> (5 formats).
+                        </listitem>
+                        <listitem>
+                            Option Lang ajoutée.
+                        </listitem>
+                        <listitem>
+                            Algorithme désormais basé sur <literal>datenum()</literal>.
+                        </listitem>
+                    </itemizedlist>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
diff --git a/scilab/modules/time/help/ja_JP/weekday.xml b/scilab/modules/time/help/ja_JP/weekday.xml
deleted file mode 100644 (file)
index 29b3835..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) INRIA -
- *
- * Copyright (C) 2012 - 2016 - Scilab Enterprises
- *
- * This file is hereby licensed under the terms of the GNU GPL v2.0,
- * pursuant to article 5.3.4 of the CeCILL v.2.1.
- * This file was originally licensed under the terms of the CeCILL v2.1,
- * and continues to be available under such terms.
- * For more information, see the COPYING file which you should have received
- * along with this program.
- *
- -->
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="ja" xml:id="weekday">
-    <refnamediv>
-        <refname>weekday</refname>
-        <refpurpose>曜日を返す</refpurpose>
-    </refnamediv>
-    <refsynopsisdiv>
-        <title>呼び出し手順</title>
-        <synopsis>[N,S] = weekday(D)
-            [N,S] = weekday(D, form)
-        </synopsis>
-    </refsynopsisdiv>
-    <refsection>
-        <title>説明</title>
-        <para>[N,S] = weekday(D) は,
-            日数 n または日付文字列Dで指定すると,
-            数値(N) および文字列(S)形式で曜日を返します.
-            入力引数 D は,日数の配列で複数の日を表すことができます.
-        </para>
-        <para>[N,S] = weekday(D, form) は,
-            数値(N) および文字列(S)形式で曜日を返しますが,
-            S の内容は form 引数に依存します.
-            form が 'long'の場合, S には完全な曜日 (例: Tuesday)が含まれます.
-            form が 'short'の場合, S には短縮形 (例: Tue) が含まれます.
-        </para>
-    </refsection>
-    <refsection>
-        <title>例</title>
-        <programlisting role="example"><![CDATA[
-today = datenum();
-[N,S] = weekday(today)
-[N,S] = weekday(today,'short')
-[N,S] = weekday(today,'long')
- ]]></programlisting>
-    </refsection>
-    <refsection role="see also">
-        <title>参照</title>
-        <simplelist type="inline">
-            <member>
-                <link linkend="datenum">datenum</link>
-            </member>
-            <member>
-                <link linkend="datevec">datevec</link>
-            </member>
-            <member>
-                <link linkend="weekday">weekday</link>
-            </member>
-        </simplelist>
-    </refsection>
-</refentry>
diff --git a/scilab/modules/time/help/ru_RU/weekday.xml b/scilab/modules/time/help/ru_RU/weekday.xml
new file mode 100644 (file)
index 0000000..752df28
--- /dev/null
@@ -0,0 +1,243 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) INRIA -
+ * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2017 - Samuel GOUGEON
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * along with this program.
+ *
+ -->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+        xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
+        xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="ru"
+        xml:id="weekday">
+    <refnamediv>
+        <refname>weekday</refname>
+        <refpurpose>Порядковый номер и название дня в неделе для указанных дат</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Синтаксис</title>
+        <synopsis>
+            [I, Names] = weekday()
+            [I, Names] = weekday(N)
+            [I, Names] = weekday(YMD)
+            [I, Names] = weekday(Y, M, D)
+            [I, Names] = weekday(dateStrings)
+            [I, Names] = weekday(.., "long")
+            [I, Names] = weekday(.., la_NG)
+        </synopsis>
+    </refsynopsisdiv>
+    <refsection role="arguments">
+        <title>Аргументы</title>
+        <variablelist>
+            <varlistentry>
+                <term>N</term>
+                <listitem>
+                    <para>
+                    Массив десятичных чисел дат, возвращаемых <literal>datenum(..)</literal>.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>YMD</term>
+                <listitem>
+                    <para>
+                    Матрица десятичных чисел с <literal>n</literal> строками и 3 столбцами. Каждый ряд определяет дату:
+                    Числа года (Y) в столбце <literal>YMD(:,1)</literal>.
+                    Порядковые номера месяцев (M) в интервале [1,12] в столбце <literal>YMD(:,2)</literal>.
+                    Порядковые номера дней (D) в интервале [1,31] в столбце <literal>YMD(:,3)</literal>.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>Y, M, D</term>
+                <listitem>
+                    <para>
+                    3 поэлементных массива десятичных целых чисел одинаковых размеров. Дата <literal>№i</literal> определяется по  <literal>D(i)/M(i)/Y(i)</literal>.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>dateStrings</term>
+                <listitem>
+                    <para>
+                    Массив строковых значений, определяющих даты в соответствии с пятью возможными
+                    форматами, описанными ниже. В этом массиве все данные должны соответствовать тому же формату:
+                    <itemizedlist>
+                        <listitem>
+                            <literal>"YYYY-MM-DD"</literal> : <literal>DD &lt; 10</literal> или/и
+                            <literal>MM &lt; 10</literal> должны иметь ноль перед числом. Например:
+                            <literal>"2017-09-07"</literal>.
+                        </listitem>
+                        <listitem>
+                            <literal>"YYYY-MM-DD HH:MN:SS.ss"</literal> или
+                            <literal>"YYYY-MM-DD какой бы вы ни пожелали"</literal> : то же, что и выше. Рассматривается только
+                            часть, расположенная перед первым пробелом.
+                        </listitem>
+                        <listitem>
+                            <literal>"D/M/Y"</literal> : Дни <literal>D &lt; 10</literal> или/и
+                            Месяцы <literal>M &lt; 10</literal> могут иметь, а могут и не иметь ноль перед числом.
+                            Например: <literal>"7/09/2017"</literal>.
+                        </listitem>
+                        <listitem>
+                            <literal>"enD/M/Y"</literal> : То же, что и выше, с префиксом "en" (для
+                            "english") и <literal>M/D</literal> вместо <literal>D/M</literal>.
+                            Например: <literal>"en7/24/2017"</literal>.
+                        </listitem>
+                        <listitem>
+                            <literal>"D-Mmm-YYYY"</literal>, где <literal>Mmm</literal> - это короткое
+                            название месяца на английском: <literal>Jan, Feb, Mar, Apr, May,
+                                Jun, Jul, Aug, Sep, Oct, Nov, Dec</literal>. Дни
+                            <literal>D &lt; 10</literal> могут иметь, а могут и не иметь ноль впереди.
+                        </listitem>
+                    </itemizedlist>
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>"long"</term>
+                <listitem>
+                    <para>
+                    Необязательное ключевое слово для получения названия дней в длинной полной форме:
+                    "Wednesday" вместо "Wed" и т.д. Может использоваться везде после входных аргументов, указывающих дни.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>la_NG</term>
+                <listitem>
+                    <para>
+                    Необязательное ключевое слово = уникальная строка, определяющая язык, на котором
+                    запрашиваются названия дней, в стандартном формате, наподобие "en_US", "fr_FR" и
+                    т.д. Может использоваться везде после входных аргументов, указывающих дни.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>I</term>
+                <listitem>
+                    <para>
+                    Массив десятичных целых чисел в интервале [1,7], имеющий размер <varname>N</varname>,
+                    <varname>YMD(:,1)</varname>, <varname>Y</varname>, <varname>M</varname> и <varname>D</varname>
+                    или <varname>dateStrings</varname>: 1 для воскресенья, 2 для понедельника, ..., 7 для субботы.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>Names</term>
+                <listitem>
+                <para>
+                    Массив текстовых слов, имеющий размер <varname>I</varname>: названия дней в неделе
+                    для указанных дат. Имена возвращаются в короткой форме (например, "Wed" для
+                    "Wednesday"), о тех пор, пока не будет использована опция <varname>"long"</varname>.
+                </para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Описание</title>
+        <para>
+            Для каждой указанной даты или, по умолчанию, сегодня, функция <function>weekday</function>
+            вычисляет и возвращает порядковый номер дня в неделе от 1 до 7. Также может быть возвращено
+            сокращённое или полное название дня на языке сессии Sciblab. Если код языка указан и язык
+            поддерживается в Scilab, то название дня будет переведено на этот язык.
+        </para>
+        <para>
+            <table border="1">
+                <tr><th>Lang</th><th>i</th><th>short</th><th>long</th><td>.......</td><th>Lang</th><th>i</th><th>short</th><th>long</th></tr>
+                <tr><td>en_US</td><td>1</td><td>Sun</td><td>Sunday</td><td>    </td><td>pt_BR</td><td>1</td><td>Dom</td><td>Domingo</td></tr>
+                <tr><td>en_US</td><td>2</td><td>Mon</td><td>Monday</td><td>    </td><td>pt_BR</td><td>2</td><td>Seg</td><td>Segunda-feira</td></tr>
+                <tr><td>en_US</td><td>3</td><td>Tue</td><td>Tuesday</td><td>    </td><td>pt_BR</td><td>3</td><td>Ter</td><td>Terça-feira</td></tr>
+                <tr><td>en_US</td><td>4</td><td>Wed</td><td>Wednesday</td><td>    </td><td>pt_BR</td><td>4</td><td>Qua</td><td>Quarta-feira</td></tr>
+                <tr><td>en_US</td><td>5</td><td>Thu</td><td>Thursday</td><td>    </td><td>pt_BR</td><td>5</td><td>Qui</td><td>Quinta-feira</td></tr>
+                <tr><td>en_US</td><td>6</td><td>Fri</td><td>Friday</td><td>    </td><td>pt_BR</td><td>6</td><td>Sex</td><td>Sexta-feira</td></tr>
+                <tr><td>en_US</td><td>7</td><td>Sat</td><td>Saturday</td><td>    </td><td>pt_BR</td><td>7</td><td>Sáb</td><td>Sábado</td></tr>
+                <tr><td>fr_FR</td><td>1</td><td>Dim.</td><td>Dimanche</td><td>    </td><td>ru_RU</td><td>1</td><td>Вск</td><td>Воскресенье</td></tr>
+                <tr><td>fr_FR</td><td>2</td><td>Lun.</td><td>Lundi</td><td>    </td><td>ru_RU</td><td>2</td><td>Пнд</td><td>Понедельник</td></tr>
+                <tr><td>fr_FR</td><td>3</td><td>Mar.</td><td>Mardi</td><td>    </td><td>ru_RU</td><td>3</td><td>Втр</td><td>Вторник</td></tr>
+                <tr><td>fr_FR</td><td>4</td><td>Mer.</td><td>Mercredi</td><td>    </td><td>ru_RU</td><td>4</td><td>Срд</td><td>Среда</td></tr>
+                <tr><td>fr_FR</td><td>5</td><td>Jeu.</td><td>Jeudi</td><td>    </td><td>ru_RU</td><td>5</td><td>Чтв</td><td>Четверг</td></tr>
+                <tr><td>fr_FR</td><td>6</td><td>Ven.</td><td>Vendredi</td><td>    </td><td>ru_RU</td><td>6</td><td>Птн</td><td>Пятница</td></tr>
+                <tr><td>fr_FR</td><td>7</td><td>Sam.</td><td>Samedi</td><td>    </td><td>ru_RU</td><td>7</td><td>Сбт</td><td>Суббота</td></tr>
+                <tr><td>ja_JP</td><td>1</td><td>日</td><td>日曜日</td><td>    </td><td>zh_CN</td><td>1</td><td>星期日</td><td>星期日</td></tr>
+                <tr><td>ja_JP</td><td>2</td><td>月</td><td>月曜日</td><td>    </td><td>zh_CN</td><td>2</td><td>星期一</td><td>星期一</td></tr>
+                <tr><td>ja_JP</td><td>3</td><td>火</td><td>火曜日</td><td>    </td><td>zh_CN</td><td>3</td><td>星期二</td><td>星期二</td></tr>
+                <tr><td>ja_JP</td><td>4</td><td>水</td><td>水曜日</td><td>    </td><td>zh_CN</td><td>4</td><td>星期三</td><td>星期三</td></tr>
+                <tr><td>ja_JP</td><td>5</td><td>木</td><td>木曜日</td><td>    </td><td>zh_CN</td><td>5</td><td>星期四</td><td>星期四</td></tr>
+                <tr><td>ja_JP</td><td>6</td><td>金</td><td>金曜日</td><td>    </td><td>zh_CN</td><td>6</td><td>星期五</td><td>星期五</td></tr>
+                <tr><td>ja_JP</td><td>7</td><td>土</td><td>土曜日</td><td>    </td><td>zh_CN</td><td>7</td><td>星期六</td><td>星期六</td></tr>
+            </table>
+        </para>
+    </refsection>
+    <refsection>
+        <title>Примеры</title>
+        <programlisting role="example">
+            <![CDATA[
+// Today
+[i, n] = weekday()
+[i, n] = weekday("long"); n
+[i, n] = weekday("long","ru_RU"); n
+// Explicit input dates
+[I, N] = weekday(     ["01/1/1970" "11/09/2001" "26/12/2004"])
+[I, N] = weekday("en"+["1/01/1970" "09/11/2001" "12/26/2004"])
+[I, N] = weekday(["1/1/1970" "11/9/2001" "26/12/2004"], "long"); N
+[I, N] = weekday(["1970-01-01" "2001-09-11" "2004-12-26"], "long"); N
+[I, N] = weekday(["1970-01-01 00:00:00" "2001-09-11 08:14:00" "2004-12-26 00:58:53"], "long"); N
+[I, N] = weekday(["1-Jan-1970" "11-Sep-2001" "26-Dec-2004"], "long"); N
+[I, N] = weekday(["1970-01-01" "en12/26/2004"]); //=> Error: все даты должны иметь одинаковый формат
+[I, N] = weekday([1970 1 1 ; 2001 9 11 ; 2004 12 26], "long"); N
+[I, N] = weekday([1970 2001 2004], [1 9 12], [1 11 26], "long"); N
+D = datenum([1970 1 1 ; 2001 9 11 ; 2004 12 26])
+[I, N] = weekday(D, "long"); N
+// Language option
+[I, N] = weekday(["1/1/1970" "11/9/2001" "26/12/2004"], "zh_CN"); N
+[I, N] = weekday(["1/1/1970" "11/9/2001" "26/12/2004"], "fr_FR", "long"); N
+ ]]>
+        </programlisting>
+    </refsection>
+    <refsection role="see also">
+        <title>Смотрите также</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="eomday">eomday</link>
+            </member>
+            <member>
+                <link linkend="datenum">datenum</link>
+            </member>
+            <member>
+                <link linkend="datevec">datevec</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection role="history">
+        <title>История</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    <itemizedlist>
+                        <listitem>
+                            Добавлены новые синтаксисы: <literal>weekday()</literal>,
+                            <literal>weekday(YMD)</literal>,
+                            <literal>weekday(Y, M, D)</literal>,
+                            <literal>weekday(dateStrings)</literal>.
+                        </listitem>
+                        <listitem>
+                            Добавлена опция языка.
+                        </listitem>
+                        <listitem>
+                            Теперь алгоритм базируется на <literal>datenum()</literal> (5 форматов).
+                        </listitem>
+                    </itemizedlist>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
+</refentry>
index 8233ecb..9560c6c 100644 (file)
@@ -1,8 +1,8 @@
-//------------------------------------------------------------------------
+//-------------------------------------------------------------------
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2005 - INRIA - Pierre MARECHAL
-//
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
+// Copyright (C) 2017 - Samuel GOUGEON
 //
 // This file is hereby licensed under the terms of the GNU GPL v2.0,
 // pursuant to article 5.3.4 of the CeCILL v.2.1.
 // For more information, see the COPYING file which you should have received
 // along with this program.
 
-//
-// Return day of week
-// Maurice Kraitchik Algorithm
-//------------------------------------------------------------------------
-
-function [N,S] = weekday(D,form)
-
-    lhs=argn(1);
-    rhs=argn(2);
-
-    // checkings
+function [I, Names] = weekday(varargin)
 
-    if rhs < 1 | rhs > 2 then
-        error(msprintf(gettext("%s: Wrong number of input arguments: %d or %d expected.\n"),"weekday",1,2));
-    end
+    lhs = argn(1);
+    rhs = argn(2);
+    long = %f;
+    lang = getlanguage();
+    fname = "weekday";
 
-    if type(D) <> 1 then
-        error(msprintf(gettext("%s: Wrong type  for input argument #%d: Real constant matrix expected.\n"),"weekday",1));
+    // CHECKING & PRE-PROCESSING PARAMETERS
+    // ====================================
+    if rhs > 5 then
+        msg = _("%s: Wrong number of input arguments: %d to %d expected.\n")
+        error(msprintf(msg, fname, 0, 5))
     end
-
-    if (rhs==2) & (form <> "long") & (form <> "short") then
-        error(msprintf(gettext("%s: Wrong value for input argument #%d: ''%s'' or ''%s'' expected.\n"),"weekday",2,"long","short"));
+    if ~isdef("varargin", "l") then
+        varargin = list();
     end
-
-    // some definitions
-
-    common_year  = [0,31,59,90,120,151,181,212,243,273,304,334,365];
-    leap_year    = [0,31,60,91,121,152,182,213,244,274,305,335,366];
-    week_numbers = [7,1,2,3,4,5,6];
-
-    week_strings_short = [gettext("Sat"), ..
-    gettext("Sun"), ..
-    gettext("Mon"), ..
-    gettext("Tue"), ..
-    gettext("Wed"), ..
-    gettext("Thu"), ..
-    gettext("Fri")];
-
-    week_strings_long = [gettext("Saturday"), ..
-    gettext("Sunday")    , ..
-    gettext("Monday")    , ..
-    gettext("Tuesday")   , ..
-    gettext("Wednesday") , ..
-    gettext("Thursday")  , ..
-    gettext("Friday")    , ..
-    gettext("Jan")];
-
-
-    if rhs==2 then
-        if form == "long" then
-            week_strings = week_strings_long;
+    if rhs>0 then
+        i = 1;
+        v = varargin(1);
+        if type(v)==1
+            // N, YMD, or Y
+            if rhs==1 | type(varargin(2))~=1    // N or YMD
+                if ndims(v)==2 & size(v,2)==3 & ..
+                    and(v(:,2)>0 & v(:,2)<13 & v(:,3)>0 & v(:,3)<32)
+                    // YMD
+                    N = datenum(v(:,1), v(:,2), v(:,3))
+                else
+                    N = v
+                end
+                varargin(1) = null();
+                i = 2;
+            else  // Y  (,M, D)
+                Y = v
+                varargin(1) = null();
+                i = 2;
+                v = varargin(1)
+                if type(v)~=1 | or(v<1) | or(v>12) | or(v~=fix(v))
+                    msg = _("%s: Argument #%d: Integers in [1,12] expected.\n")
+                    error(msprintf(msg, fname, 2))
+                end
+                if rhs==2 | type(varargin(2))~=1
+                    msg = _("%s: Argument #%d missing: Integers in [1,31] expected.\n")
+                    error(msprintf(msg, fname, 3))
+                end
+                M = v;
+                varargin(1) = null()
+                i = 3;
+                v = varargin(1);
+                if or(v<1) | or(v>31) | or(v~=fix(v))
+                    msg = _("%s: Argument #%d: Integers in [1,31] expected.\n")
+                    error(msprintf(msg, fname, 3))
+                end
+                D = v;
+                varargin(1) = null();
+                i = 4;
+                if ~and(size(Y)==size(M)) | ~and(size(M)==size(D))
+                    msg = _("%s: Arguments #%d to #%d: Same sizes expected.\n")
+                    error(msprintf(msg, fname, 1, 3))
+                end
+                N = datenum(Y, M, D);
+            end
         else
-            week_strings = week_strings_short;
+            if type(v)~=10
+                msg = _("%s: Argument #%d: Numbers or texts expected.\n")
+                error(msprintf(msg, fname, i))
+            end
+            if or(length(v)>5)  // => dates
+                s = size(v);
+                v = v(:);
+                ok = %f;
+                // Parsing against
+                // DD-Mmm-YYYY | DD/MM/YYYY | YYYY-MM-DD | YYYY-MM-DD HH:MN:SS.ss
+                // v = ["2001-12-21"        "2015-07-25 14:57:35" ..
+                //      "2007-01-45 hdgtf"  "1875-04-17 23:57:04.145" ];
+                tmp = grep(v, "|^\-{0,1}[0-9]{4}\-[0-9]{2}\-[0-9]{2}|","r");
+                if and(tmp==(1:size(v,"*")))
+                    // YYYY-MM-DD | YYYY-MM-DD HH:MN:SS.ss
+                    // Triming the " HH:MN:SS.sss" trail
+                    tmp = strcspn(v, " ");
+                    v = strncpy(v, tmp);
+                    v = csvTextScan(v, "-", [], "double");
+                    ok = %t;
+                else
+                    if tmp~=[]
+                        msg = _("%s: Argument #%d: All dates must have the same format.\n")
+                        error(msprintf(msg, fname, 1))
+                    end
+                end
+                if ~ok
+                    //  Parsing against D/M/YYYY
+                    // v = ["1/2/1234", "12/7/4321", "9/09/8754a", "08/04/457 abc"]
+                    tmp = grep(v, "=^[0-9]{1,2}\/[0-9]{1,2}\/\-{0,1}[0-9]{1,4}(\s.*|)$=","r");
+                    if and(tmp==(1:size(v,"*")))
+                        // "D/M/YYYY" | "DD/M/YYY" | "D/MM/YYY" | "DD/MM/YYYY" | "D/M/YY abc"
+                        // Triming the " blabla" trail
+                        tmp = strcspn(v, " ");
+                        v = strncpy(v, tmp);
+                        v = csvTextScan(v, "/", [], "double");
+                        v(:,[1 3]) = v(:,[3 1]);
+                        ok = %t;
+                    else
+                        if tmp~=[]
+                           msg = _("%s: Argument #%d: All dates must have the same format.\n")
+                           error(msprintf(msg, fname, 1))
+                        end
+                    end
+                end
+                if ~ok
+                    //  Parsing against enM/D/YYYY
+                    // v = ["en2/1/1234", "en7/24/1958", "en12/09/8754a", "en08/04/457 abc"]
+                    tmp = grep(v, "=^en[0-9]{1,2}\/[0-9]{1,2}\/\-{0,1}[0-9]{1,4}(\s.*|)$=i","r");
+                    if and(tmp==(1:size(v,"*")))
+                        //"enM/D/YYYY" |"enMM/D/YYY" |"enM/DD/YYY" |"enMM/DD/YYYY" |"enM/D/YY abc"
+                        // Triming the prefix "en"
+                        v = part(v, 3:$);
+                        // Triming the " blabla" trail
+                        tmp = strcspn(v, " ");
+                        v = strncpy(v, tmp);
+                        v = csvTextScan(v, "/", [], "double");
+                        v(:,1:3) = v(:,[3 1 2]);
+                        ok = %t;
+                    else
+                        if tmp~=[]
+                           msg = _("%s: Argument #%d: All dates must have the same format.\n")
+                           error(msprintf(msg, fname, 1))
+                        end
+                    end
+                end
+                if ~ok
+                    //  Parsing against DD-Mmm-YYYY
+                    // v = ["2-Dec-847", "07-Jun-2451", "07-JUN-2451", "15-Fav-527"]
+                    //         ok            ok             nok            nok
+                    tmp = grep(v, "=^[0-9]{1,2}\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\-[0-9]{1,4}$=","r");
+                    if and(tmp==(1:size(v,"*")))
+                        tmp = csvTextScan(v, "-", [], "string");
+                        v = zeros(tmp);
+                        v(:,[3 1]) = evstr(tmp(:,[1 3]));
+                        M = ["Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"]
+                        for i = 1:12
+                            v(find(tmp(:,2)==M(i)),2) = i;
+                        end
+                        ok = %t;
+                    else
+                        if tmp~=[]
+                           msg = _("%s: Argument #%d: All dates must have the same format.\n")
+                           error(msprintf(msg, fname, 1))
+                        end
+                    end
+                end
+                if ~ok
+                   msg = _("%s: Argument #%d: Wrong dates format.\n")
+                   error(msprintf(msg, fname, 1))
+                end
+                if ~and(v(:,2)>0 & v(:,2)<13)
+                    msg = _("%s: Argument #%d: Month indices expected in [1,12].\n")
+                    error(msprintf(msg, fname, 1))
+                end
+                if ~and(v(:,2)>0 & v(:,2)<32)
+                    msg = _("%s: Argument #%d: Day indices expected in [1,31].\n")
+                    error(msprintf(msg, fname, 1))
+                end
+                N = datenum(v(:,1), v(:,2), v(:,3));
+                N = matrix(N, s);
+                varargin(1) = null();
+                i = 2;
+            end
         end
-    else
-        week_strings = week_strings_short;
     end
-
-
-    // Algorithm
-
-    [nr,nc]  = size(D);
-
-    if nc == 1 then
-        common_year = common_year';
-        leap_year   = leap_year';
+    if ~isdef("N","l") then
+        N = datenum();
     end
 
-    month_day_mat   = ones(nr,nc);
-
-    m               = ones(nr,nc);
-    y               = ones(nr,nc);
-    d               = ones(nr,nc);
-
-    Y        = floor(D/365.2425);
-    temp     = D - (365.0*Y + ceil(0.25*Y)- ceil(0.01*Y) + ceil(0.0025*Y));
-
-    mask     = find(temp <= 0);
-    if ~isempty(mask)
-        Y(mask)  = Y(mask) - 1;
-        D(mask)  = D(mask) - (365.0*Y(mask) + ceil(0.25*Y(mask)) - ceil(0.01*Y(mask)) + ceil(0.0025*Y(mask)));
-        D(~mask) = temp(~mask);
-    else
-        D = temp;
-    end
-
-    M = int(D/29);
-    idx_leap_year = isLeapYear(Y);
-
-    if ~isempty(M(idx_leap_year))
-        month_day_mat(idx_leap_year)  = leap_year(M(idx_leap_year)+1);
-    end
-    if ~isempty(M(~idx_leap_year))
-        month_day_mat(~idx_leap_year) = common_year(M(~idx_leap_year)+1);
-    end
-
-    if ~isempty(M( D>month_day_mat )) then
-        M( D>month_day_mat ) = M( D>month_day_mat )+1;
-    end
+    // Parsing Options, if any:
+    // -----------------------
+    for o = varargin
+        if type(o)~=10 | size(o,"*")>1
+            msg = _("%s: Argument #%d: Single text word expected.\n")
+            error(msprintf(msg, fname, i))
+        end
+        if o=="long"
+            long = %t
+        elseif o=="short"
+        elseif length(o)==5
+            if grep(o, "|^[a-z]{2}_[A-Z]{2}$|", "r")==[]
+                msg = _("%s: Argument #%d: Wrong langage code.\n")
+                error(msprintf(msg, fname, i))
+            end
+            lang = o;
+        else
+            msg = _("%s: Argument #%d: Unknown option.\n")
+            error(msprintf(msg, fname, i))
+        end
+        i = i+1;
 
-    if ~isempty(M(idx_leap_year))
-        month_day_mat(idx_leap_year)  = leap_year(M(idx_leap_year));
-    end
-    if ~isempty(M(~idx_leap_year))
-        month_day_mat(~idx_leap_year) = common_year(M(~idx_leap_year));
     end
 
-    d = D - month_day_mat;
-
-    m(M==1) = 13;
-    m(M==2) = 14;
-
-    if ~isempty(Y( M==1 | M==2 )) then
-        y( M==1 | M==2 ) = Y( M==1 | M==2 ) - 1;
+    // PROCESSING
+    // ==========
+    // Day index
+    I = pmodulo(floor(N-657435), 7)+1
+    // Day name
+    if %f  // only for gettext's parser
+       [_("Sunday") _("Monday") _("Tuesday") _("Wednesday") _("Thursday") _("Friday") _("Saturday")];
+       [_("Sun") _("Mon") _("Tue") _("Wed") _("Thu") _("Fri") _("Sat")];
     end
-    
-    if ~isempty(M( M<>1 & M<>2 )) then
-        m( M<>1 & M<>2 ) = M( M<>1 & M<>2 );
+    if long then
+        dayNames = ..
+       ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"]
+    else
+        dayNames = ["Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat"]
     end
-    if ~isempty(Y( M<>1 & M<>2 )) then
-        y( M<>1 & M<>2 ) = Y( M<>1 & M<>2 );
+    Names = matrix(dayNames(I), size(N))
+        // Translation
+    L = getlanguage();
+    if lang~="en_US" then
+        setlanguage(lang);
+        Names = _(Names);
+        setlanguage(L);
     end
-
-    n =  modulo(  (d + floor(2*m) + floor(3*(m+1)/5) + y + floor(y/4) - floor(y/100) + floor(y/400) + 2)  ,  7  );
-
-    N = matrix( week_numbers(n+1) , nr, nc );
-    S = matrix( week_strings(n+1) , nr, nc );
-
 endfunction
diff --git a/scilab/modules/time/tests/unit_tests/weekday.tst b/scilab/modules/time/tests/unit_tests/weekday.tst
new file mode 100644 (file)
index 0000000..d43ce0c
--- /dev/null
@@ -0,0 +1,104 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2017 - Samuel GOUGEON
+//
+// This file is hereby licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// This file was originally licensed under the terms of the CeCILL v2.1,
+// and continues to be available under such terms.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+// =============================================================================
+
+// <-- CLI SHELL MODE -->
+// <-- NO CHECK REF -->
+
+// Current date
+assert_checkequal(execstr("weekday()", "errcatch"),0);
+assert_checkequal(execstr("weekday(""long"")", "errcatch"),0);
+assert_checkequal(execstr("weekday(""short"")", "errcatch"),0);
+assert_checkequal(execstr("weekday(""long"",""ru_RU"")", "errcatch"),0);
+assert_checkequal(execstr("weekday(""ru_RU"")", "errcatch"),0);
+assert_checkequal(execstr("weekday(""ru_RU"", ""long"")", "errcatch"),0);
+
+// Checking output sizes
+[n, t] = weekday();
+assert_checkequal(size(n), [1 1]);
+assert_checkequal(size(t), [1 1]);
+[n, t] = weekday(740000);
+assert_checkequal(size(n), [1 1]);
+assert_checkequal(size(t), [1 1]);
+[n, t] = weekday([740000 ; 740008]);
+assert_checkequal(size(n), [2 1]);
+assert_checkequal(size(t), [2 1]);
+[n, t] = weekday([740000  740008]);
+assert_checkequal(size(n), [1 2]);
+assert_checkequal(size(t), [1 2]);
+[n, t] = weekday([740000 ; 740008], "long");
+assert_checkequal(size(n), [2 1]);
+assert_checkequal(size(t), [2 1]);
+[n, t] = weekday([740000  740008], "long");
+assert_checkequal(size(n), [1 2]);
+assert_checkequal(size(t), [1 2]);
+[n, t] = weekday([740000  740008], "ru_RU");
+assert_checkequal(size(n), [1 2]);
+assert_checkequal(size(t), [1 2]);
+[n, t] = weekday([740000  740008], "ru_RU", "long");
+assert_checkequal(size(n), [1 2]);
+assert_checkequal(size(t), [1 2]);
+
+assert_checkequal(size(weekday([2015 6 11])), [1 1]);
+assert_checkequal(size(weekday([2015 2015]', [2 10]', [21 3]')), [2 1]);
+assert_checkequal(size(weekday([2015 2015], [2 10], [21 3])), [1 2]);
+
+[n0, t0] = weekday(["9/7/2017" "17/7/2017" "25/7/2017"]);
+assert_checkequal(n0, [1 2 3]);
+[n, t] = weekday(["09/7/2017" "17/07/2017" "25/07/2017"]);
+assert_checkequal(n, n0);
+assert_checkequal(t, t0);
+[n0, t0] = weekday("en"+["7/9/2017" "7/17/2017" "7/25/2017"]);
+assert_checkequal(n0, [1 2 3]);
+[n, t] = weekday("en"+["7/09/2017" "07/17/2017" "07/25/2017"]);
+assert_checkequal(n, n0);
+assert_checkequal(t, t0);
+[n, t] = weekday(["2017-07-09" "2017-07-17" "2017-07-25"]);
+assert_checkequal(n, n0);
+assert_checkequal(t, t0);
+[n, t] = weekday(["2017-07-09 14:27:08.2" "2017-07-17 abcd" "2017-07-25"]);
+assert_checkequal(n, n0);
+assert_checkequal(t, t0);
+[n, t] = weekday(["9-Jul-2017" "17-Jul-2017" "25-Jul-2017"]);
+assert_checkequal(n, n0);
+assert_checkequal(t, t0);
+d = [ 2017  7  9
+      2017  7  17
+      2017  7  25
+    ];
+[n, t] = weekday(d);
+assert_checkequal(n, n0(:));
+assert_checkequal(t, t0(:));
+[n, t] = weekday([736885 736893 736901]);
+assert_checkequal(n, n0);
+assert_checkequal(t, t0);
+
+// Options
+// -------
+[n0, t] = weekday(["9/7/2017" "17/7/2017" ; "25/7/2017" "31/07/2017"],"fr_FR");
+assert_checkequal(n0, [1 2 ; 3 2]);
+assert_checkequal(t, ["Dim." "Lun." ; "Mar." "Lun."]);
+[n, t] = weekday(["9/7/2017" "17/7/2017" ; "25/7/2017" "31/07/2017"],"fr_FR","long");
+assert_checkequal(n, n0);
+assert_checkequal(t, ["Dimanche" "Lundi" ; "Mardi" "Lundi"]);
+[n, t] = weekday(["9/7/2017" "17/7/2017" ; "25/7/2017" "31/07/2017"],"long","fr_FR");
+assert_checkequal(n, n0);
+assert_checkequal(t, ["Dimanche" "Lundi" ; "Mardi" "Lundi"]);
+lang = getlanguage();
+[n0, t0] = weekday(["9/7/2017" "17/7/2017" ; "25/7/2017" "31/07/2017"]);
+[n, t] = weekday(["9/7/2017" "17/7/2017" ; "25/7/2017" "31/07/2017"], lang);
+assert_checkequal(n, n0);
+assert_checkequal(t, t0);
+[n, t] = weekday(["9/7/2017" "17/7/2017" ; "25/7/2017" "31/07/2017"],"en_US","long");
+assert_checkequal(t, ["Sunday" "Monday" ; "Tuesday" "Monday"]);
+[n, t] = weekday(["9/7/2017" "17/7/2017" ; "25/7/2017" "31/07/2017"],"long","ru_RU");
+assert_checkequal(t, ["Воскресенье" "Понедельник" ; "Вторник" "Понедельник"]);
+