Mercurial > hg > octave-lyh
annotate scripts/time/weekday.m @ 14237:11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Add clf() to all demos using plot features to get reproducibility.
Use 64 as input to all colormaps (jet (64)) to get reproducibility.
* bicubic.m, cell2mat.m, celldisp.m, cplxpair.m, interp1.m, interp2.m,
interpft.m, interpn.m, profile.m, profshow.m, convhull.m, delaunay.m,
griddata.m, inpolygon.m, voronoi.m, autumn.m, bone.m, contrast.m, cool.m,
copper.m, flag.m, gmap40.m, gray.m, hot.m, hsv.m, image.m, imshow.m, jet.m,
ocean.m, pink.m, prism.m, rainbow.m, spring.m, summer.m, white.m, winter.m,
condest.m, onenormest.m, axis.m, clabel.m, colorbar.m, comet.m, comet3.m,
compass.m, contour.m, contour3.m, contourf.m, cylinder.m, daspect.m,
ellipsoid.m, errorbar.m, ezcontour.m, ezcontourf.m, ezmesh.m, ezmeshc.m,
ezplot.m, ezplot3.m, ezpolar.m, ezsurf.m, ezsurfc.m, feather.m, fill.m,
fplot.m, grid.m, hold.m, isosurface.m, legend.m, loglog.m, loglogerr.m,
pareto.m, patch.m, pbaspect.m, pcolor.m, pie.m, pie3.m, plot3.m, plotmatrix.m,
plotyy.m, polar.m, quiver.m, quiver3.m, rectangle.m, refreshdata.m, ribbon.m,
rose.m, scatter.m, scatter3.m, semilogx.m, semilogxerr.m, semilogy.m,
semilogyerr.m, shading.m, slice.m, sombrero.m, stairs.m, stem.m, stem3.m,
subplot.m, surf.m, surfc.m, surfl.m, surfnorm.m, text.m, title.m, trimesh.m,
triplot.m, trisurf.m, uigetdir.m, uigetfile.m, uimenu.m, uiputfile.m,
waitbar.m, xlim.m, ylim.m, zlim.m, mkpp.m, pchip.m, polyaffine.m, spline.m,
bicgstab.m, cgs.m, gplot.m, pcg.m, pcr.m, treeplot.m, strtok.m, demo.m,
example.m, rundemos.m, speed.m, test.m, calendar.m, datestr.m, datetick.m,
weekday.m: Revamp %!demos to use Octave coding conventions on spacing, etc.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Fri, 20 Jan 2012 12:59:53 -0800 |
parents | 72c96de7a403 |
children | bc924baa2c4e |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14093
diff
changeset
|
1 ## Copyright (C) 2000-2012 Paul Kienzle |
5687 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5687 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5687 | 18 |
19 ## -*- texinfo -*- | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{n}, @var{s}] =} weekday (@var{d}) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
21 ## @deftypefnx {Function File} {[@var{n}, @var{s}] =} weekday (@var{d}, @var{format}) |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
22 ## Return the day of the week as a number in @var{n} and as a string in @var{s}. |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
23 ## The days of the week are numbered 1--7 with the first day being Sunday. |
5687 | 24 ## |
25 ## @var{d} is a serial date number or a date string. | |
26 ## | |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
27 ## If the string @var{format} is not present or is equal to "short" then |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
28 ## @var{s} will contain the abbreviated name of the weekday. If @var{format} |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
29 ## is "long" then @var{s} will contain the full name. |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
30 ## |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
31 ## Table of return values based on @var{format}: |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
32 ## |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13856
diff
changeset
|
33 ## @multitable @columnfractions .06 .13 .16 |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
34 ## @headitem @var{n} @tab "short" @tab "long" |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
35 ## @item 1 @tab Sun @tab Sunday |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
36 ## @item 2 @tab Mon @tab Monday |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
37 ## @item 3 @tab Tue @tab Tuesday |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
38 ## @item 4 @tab Wed @tab Wednesday |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
39 ## @item 5 @tab Thu @tab Thursday |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
40 ## @item 6 @tab Fri @tab Friday |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
41 ## @item 7 @tab Sat @tab Saturday |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
42 ## @end multitable |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
43 ## |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
44 ## @seealso{eomday, is_leap_year, calendar, datenum, datevec} |
5687 | 45 ## @end deftypefn |
46 | |
47 ## Author: pkienzle <pkienzle@users.sf.net> | |
48 ## Created: 10 October 2001 (CVS) | |
49 ## Adapted-By: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com> | |
50 | |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
51 function [d, s] = weekday (d, format = "short") |
5687 | 52 |
53 if (nargin < 1 || nargin > 2) | |
5823 | 54 print_usage (); |
5687 | 55 endif |
56 | |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
57 if (iscellstr (d) || isnumeric (d)) |
7434 | 58 endsize = size (d); |
59 elseif (ischar (d)) | |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
60 endsize = [rows(d), 1]; |
7434 | 61 endif |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
62 if (ischar (d) || iscellstr (d)) |
7434 | 63 ## Make sure the date is numeric |
64 d = datenum (d); | |
65 endif | |
66 ## Find the offset from a known Sunday (2008-Jan-6), mod 7. | |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
67 d = floor (reshape (mod (d - 733048, 7), endsize)); |
7434 | 68 ## Make Saturdays a 7 and not a 0. |
69 d(!d) = 7; | |
5687 | 70 |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
71 if (isargout (2)) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
72 if (strcmpi (format, "long")) |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
73 names = {"Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" ... |
10549 | 74 "Friday" "Saturday"}; |
5687 | 75 else |
7434 | 76 names = {"Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat"}; |
5687 | 77 endif |
7434 | 78 s = strvcat (names(d)); |
5687 | 79 endif |
80 | |
81 endfunction | |
82 | |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
83 |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
84 %!demo |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
85 %! ## Current weekday |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
86 %! [n, s] = weekday (now ()) |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
87 |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
88 %!demo |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
89 %! ## Weekday from datenum input |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
90 %! [n, s] = weekday (728647) |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
91 |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
92 %!demo |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
93 %! ## Weekday of new millennium from datestr input |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
94 %! [n, s] = weekday ("1-Jan-2000") |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
95 |
5687 | 96 # tests |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
97 %!assert (weekday (728647), 2) |
7434 | 98 ## Test vector inputs for both directions |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
99 %!assert (weekday ([728647 728648]), [2 3]) |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
100 %!assert (weekday ([728647;728648]), [2;3]) |
7434 | 101 ## Test a full week before our reference day |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
102 %!assert (weekday ("19-Dec-1994"), 2) |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
103 %!assert (weekday ("20-Dec-1994"), 3) |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
104 %!assert (weekday ("21-Dec-1994"), 4) |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
105 %!assert (weekday ("22-Dec-1994"), 5) |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
106 %!assert (weekday ("23-Dec-1994"), 6) |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
107 %!assert (weekday ("24-Dec-1994"), 7) |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
108 %!assert (weekday ("25-Dec-1994"), 1) |
7434 | 109 ## Test our reference day |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
110 %!assert (weekday ("6-Jan-2008"), 1) |
7434 | 111 ## Test a full week after our reference day |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
112 %!assert (weekday ("1-Feb-2008"), 6) |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
113 %!assert (weekday ("2-Feb-2008"), 7) |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
114 %!assert (weekday ("3-Feb-2008"), 1) |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
115 %!assert (weekday ("4-Feb-2008"), 2) |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
116 %!assert (weekday ("5-Feb-2008"), 3) |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
117 %!assert (weekday ("6-Feb-2008"), 4) |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
118 %!assert (weekday ("7-Feb-2008"), 5) |
7434 | 119 ## Test fractional dates |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
120 %!assert (weekday (728647.1), 2) |
13170
796dc1d75e06
Fix incorrect newline in weekday.m (bug #34347)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11523
diff
changeset
|
121 ## Test "long" option |
796dc1d75e06
Fix incorrect newline in weekday.m (bug #34347)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11523
diff
changeset
|
122 %!test |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
123 %! [n, s] = weekday ("25-Dec-1994", "long"); |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
124 %! assert (n, 1); |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13170
diff
changeset
|
125 %! assert (s, "Sunday"); |
13170
796dc1d75e06
Fix incorrect newline in weekday.m (bug #34347)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11523
diff
changeset
|
126 |