Mercurial > hg > octave-terminal
changeset 7434:600a3af7963e
[project @ 2008-02-01 06:32:06 by jwe]
author | jwe |
---|---|
date | Fri, 01 Feb 2008 06:34:12 +0000 |
parents | 402168152bb9 |
children | 464a55f1a5c2 |
files | scripts/ChangeLog scripts/miscellaneous/edit.m scripts/time/eomday.m scripts/time/weekday.m |
diffstat | 4 files changed, 65 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,5 +1,13 @@ +2008-02-01 Bill Denney <bill@denney.ws> + + * time/weekday.m: Allow vector inputs and speed up. + * time/eomday.m: Return column vector for column vector inputs. + 2008-01-30 John W. Eaton <jwe@octave.org> + * miscellaneous/edit.m: Use "## Created: DATE" instead of "initial + revision". + * plot/Makefile.in (SOURCES): Include __plt2sv__.m and __plt2vs__.m in the list.
--- a/scripts/miscellaneous/edit.m +++ b/scripts/miscellaneous/edit.m @@ -263,8 +263,7 @@ ## Fill in the revision string. now = localtime (time); - revs = strcat (strftime ("%Y-%m-%d", now), " ", FUNCTION.AUTHOR, " ", - FUNCTION.EMAIL, "\n* Initial revision"); + revs = strcat ("Created: ", strftime ("%Y-%m-%d", now)); ## Fill in the copyright string. copyright = strcat (strftime ("Copyright (C) %Y ", now), FUNCTION.AUTHOR); @@ -291,7 +290,7 @@ along with this program; if not, write to the Free Software\n\ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\ "); - tail = strcat (author, "\n\n", revs); + tail = strcat (author, "\n", revs); case "BSD" head = strcat (copyright, "\n\n", "\ @@ -317,18 +316,17 @@ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n\ SUCH DAMAGE.\ "); - tail = strcat (author, "\n\n", revs); + tail = strcat (author, "\n", revs); case "PD" head = ""; - tail = strcat (author, "\n\n", - "This program is granted to the public domain\n\n", - revs); + tail = strcat (author, "\n", revs, "\n\n", + "This program is granted to the public domain."); otherwise head = ""; tail = strcat (copyright, "\n\n", FUNCTION.LICENSE, "\n", - author, "\n\n", revs); + author, "\n", revs); endswitch ## Generate the function template. @@ -401,11 +399,10 @@ endfunction -## default_user (form) -## Returns the name associated with the current user ID. +## Return the name associated with the current user ID. ## -## If form==1 return the full name. This will be the -## default author. If form==0 return the login name. +## If LONG_FORM is 1, return the full name. This will be the +## default author. Otherwise return the login name. ## login@host will be the default email address. function ret = default_user (long_form) @@ -418,6 +415,10 @@ endif elseif (long_form) ret = ent.gecos; + pos = strfind (ret, ","); + if (! isempty (pos)) + ret = ret(1:pos-1); + endif else ret = ent.name; endif
--- a/scripts/time/eomday.m +++ b/scripts/time/eomday.m @@ -19,7 +19,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {@var{e} =} eomday (@var{y}, @var{m}) ## Return the last day of the month @var{m} for the year @var{y}. -## @seealso{datenum, datevec, weekday} +## @seealso{datenum, datevec, weekday, eomdate} ## @end deftypefn ## Author: pkienzle <pkienzle@users.sf.net> @@ -33,7 +33,7 @@ endif eom = [31, 28, 31, 30 ,31, 30, 31, 31, 30, 31, 30, 31]; - e = eom(m); + e = reshape (eom(m), size (m)); e += (m == 2) & (mod (y, 4) == 0 & (mod (y, 100) != 0 | mod (y, 400) == 0)); endfunction @@ -49,6 +49,7 @@ %!assert(eomday(1:3,1:3),[31,28,31]) %!assert(eomday(1:2000,2)',datevec(datenum(1:2000,3,0))(:,3)) %!assert([1900:1999](find(eomday(1900:1999,2*ones(1,100))==29)),[1904,1908,1912,1916,1920,1924,1928,1932,1936,1940,1944,1948,1952,1956,1960,1964,1968,1972,1976,1980,1984,1988,1992,1996]) +%!assert(eomday([2004;2005], [2;2]), [29;28]) # demos %!demo %! y = 1900:1999;
--- a/scripts/time/weekday.m +++ b/scripts/time/weekday.m @@ -1,4 +1,4 @@ -## Copyright (C) 2000, 2001, 2004, 2005, 2006, 2007 Paul Kienzle +## Copyright (C) 2000, 2001, 2004, 2005, 2006, 2007, 2008 Paul Kienzle ## ## This file is part of Octave. ## @@ -34,7 +34,7 @@ ## Created: 10 October 2001 (CVS) ## Adapted-By: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com> -function [n, s] = weekday (d, form) +function [d, s] = weekday (d, form) if (nargin < 1 || nargin > 2) print_usage (); @@ -44,24 +44,57 @@ form = "short"; endif - v = datevec (d); - t = strptime (sprintf ("%d-%d-%d", v(3), v(2), v(1)), "%d-%m-%Y"); - - n = t.wday + 1; + if (iscell (d) || isnumeric (d)) + endsize = size (d); + elseif (ischar (d)) + endsize = [size(d, 1), 1]; + endif + if (ischar (d) || iscell (d)) + ## Make sure the date is numeric + d = datenum (d); + endif + ## Find the offset from a known Sunday (2008-Jan-6), mod 7. + d = floor (reshape (mod(d - 733048, 7), endsize)); + ## Make Saturdays a 7 and not a 0. + d(!d) = 7; if (nargout > 1) if (strcmpi (form, "long")) - s = strftime ("%A", t); + names = {"Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" + "Friday" "Saturday"}; else - s = strftime ("%a", t); + names = {"Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat"}; endif + s = strvcat (names(d)); endif endfunction # tests %!assert(weekday(728647),2) +## Test vector inputs for both directions +%!assert(weekday([728647 728648]), [2 3]) +%!assert(weekday([728647;728648]), [2;3]) +## Test a full week before our reference day %!assert(weekday('19-Dec-1994'),2) +%!assert(weekday('20-Dec-1994'),3) +%!assert(weekday('21-Dec-1994'),4) +%!assert(weekday('22-Dec-1994'),5) +%!assert(weekday('23-Dec-1994'),6) +%!assert(weekday('24-Dec-1994'),7) +%!assert(weekday('25-Dec-1994'),1) +## Test our reference day +%!assert(weekday('6-Jan-2008'),1) +## Test a full week after our reference day +%!assert(weekday('1-Feb-2008'),6) +%!assert(weekday('2-Feb-2008'),7) +%!assert(weekday('3-Feb-2008'),1) +%!assert(weekday('4-Feb-2008'),2) +%!assert(weekday('5-Feb-2008'),3) +%!assert(weekday('6-Feb-2008'),4) +%!assert(weekday('7-Feb-2008'),5) +## Test fractional dates +%!assert(weekday(728647.1),2) # demos %!demo %! [n, s] = weekday (now ())