annotate scripts/time/datevec.m @ 14363:f3d52523cde1

Use Octave coding conventions in all m-file %!test blocks * wavread.m, acosd.m, acot.m, acotd.m, acoth.m, acsc.m, acscd.m, acsch.m, asec.m, asecd.m, asech.m, asind.m, atand.m, cosd.m, cot.m, cotd.m, coth.m, csc.m, cscd.m, csch.m, sec.m, secd.m, sech.m, sind.m, tand.m, accumarray.m, accumdim.m, bitcmp.m, bitget.m, bitset.m, blkdiag.m, cart2pol.m, cart2sph.m, celldisp.m, chop.m, circshift.m, colon.m, common_size.m, cplxpair.m, cumtrapz.m, curl.m, dblquad.m, deal.m, divergence.m, flipdim.m, fliplr.m, flipud.m, genvarname.m, gradient.m, idivide.m, int2str.m, interp1.m, interp1q.m, interp2.m, interp3.m, interpft.m, interpn.m, isa.m, isdir.m, isequal.m, isequalwithequalnans.m, issquare.m, logspace.m, nargchk.m, narginchk.m, nargoutchk.m, nextpow2.m, nthargout.m, num2str.m, pol2cart.m, polyarea.m, postpad.m, prepad.m, profile.m, profshow.m, quadgk.m, quadv.m, randi.m, rat.m, repmat.m, rot90.m, rotdim.m, shift.m, shiftdim.m, sph2cart.m, structfun.m, trapz.m, triplequad.m, convhull.m, dsearch.m, dsearchn.m, griddata3.m, griddatan.m, rectint.m, tsearchn.m, __makeinfo__.m, doc.m, get_first_help_sentence.m, help.m, type.m, unimplemented.m, which.m, imread.m, imwrite.m, dlmwrite.m, fileread.m, is_valid_file_id.m, strread.m, textread.m, textscan.m, commutation_matrix.m, cond.m, condest.m, cross.m, duplication_matrix.m, expm.m, housh.m, isdefinite.m, ishermitian.m, issymmetric.m, logm.m, normest.m, null.m, onenormest.m, orth.m, planerot.m, qzhess.m, rank.m, rref.m, trace.m, vech.m, ans.m, bincoeff.m, bug_report.m, bzip2.m, comma.m, compare_versions.m, computer.m, edit.m, fileparts.m, fullfile.m, getfield.m, gzip.m, info.m, inputname.m, isappdata.m, isdeployed.m, ismac.m, ispc.m, isunix.m, list_primes.m, ls.m, mexext.m, namelengthmax.m, news.m, orderfields.m, paren.m, recycle.m, rmappdata.m, semicolon.m, setappdata.m, setfield.m, substruct.m, symvar.m, ver.m, version.m, warning_ids.m, xor.m, fminbnd.m, fsolve.m, fzero.m, lsqnonneg.m, optimset.m, pqpnonneg.m, sqp.m, matlabroot.m, __gnuplot_drawnow__.m, __plt_get_axis_arg__.m, ancestor.m, cla.m, clf.m, close.m, colorbar.m, colstyle.m, comet3.m, contourc.m, figure.m, gca.m, gcbf.m, gcbo.m, gcf.m, ginput.m, graphics_toolkit.m, gtext.m, hggroup.m, hist.m, hold.m, isfigure.m, ishghandle.m, ishold.m, isocolors.m, isonormals.m, isosurface.m, isprop.m, legend.m, line.m, loglog.m, loglogerr.m, meshgrid.m, ndgrid.m, newplot.m, orient.m, patch.m, plot3.m, plotyy.m, __print_parse_opts__.m, quiver3.m, refreshdata.m, ribbon.m, semilogx.m, semilogxerr.m, semilogy.m, stem.m, stem3.m, subplot.m, title.m, uigetfile.m, view.m, whitebg.m, compan.m, conv.m, deconv.m, mkpp.m, mpoles.m, pchip.m, poly.m, polyaffine.m, polyder.m, polyfit.m, polygcd.m, polyint.m, polyout.m, polyval.m, polyvalm.m, ppder.m, ppint.m, ppjumps.m, ppval.m, residue.m, roots.m, spline.m, intersect.m, ismember.m, powerset.m, setdiff.m, setxor.m, union.m, unique.m, autoreg_matrix.m, bartlett.m, blackman.m, detrend.m, fftconv.m, fftfilt.m, fftshift.m, freqz.m, hamming.m, hanning.m, ifftshift.m, sinc.m, sinetone.m, sinewave.m, unwrap.m, bicg.m, bicgstab.m, gmres.m, gplot.m, nonzeros.m, pcg.m, pcr.m, spaugment.m, spconvert.m, spdiags.m, speye.m, spfun.m, spones.m, sprand.m, sprandsym.m, spstats.m, spy.m, svds.m, treelayout.m, bessel.m, beta.m, betaln.m, factor.m, factorial.m, isprime.m, lcm.m, legendre.m, nchoosek.m, nthroot.m, perms.m, pow2.m, primes.m, reallog.m, realpow.m, realsqrt.m, hadamard.m, hankel.m, hilb.m, invhilb.m, magic.m, rosser.m, vander.m, __finish__.m, center.m, cloglog.m, corr.m, cov.m, gls.m, histc.m, iqr.m, kendall.m, kurtosis.m, logit.m, mahalanobis.m, mean.m, meansq.m, median.m, mode.m, moment.m, ols.m, ppplot.m, prctile.m, probit.m, quantile.m, range.m, ranks.m, run_count.m, runlength.m, skewness.m, spearman.m, statistics.m, std.m, table.m, var.m, zscore.m, betacdf.m, betainv.m, betapdf.m, betarnd.m, binocdf.m, binoinv.m, binopdf.m, binornd.m, cauchy_cdf.m, cauchy_inv.m, cauchy_pdf.m, cauchy_rnd.m, chi2cdf.m, chi2inv.m, chi2pdf.m, chi2rnd.m, discrete_cdf.m, discrete_inv.m, discrete_pdf.m, discrete_rnd.m, empirical_cdf.m, empirical_inv.m, empirical_pdf.m, empirical_rnd.m, expcdf.m, expinv.m, exppdf.m, exprnd.m, fcdf.m, finv.m, fpdf.m, frnd.m, gamcdf.m, gaminv.m, gampdf.m, gamrnd.m, geocdf.m, geoinv.m, geopdf.m, geornd.m, hygecdf.m, hygeinv.m, hygepdf.m, hygernd.m, kolmogorov_smirnov_cdf.m, laplace_cdf.m, laplace_inv.m, laplace_pdf.m, laplace_rnd.m, logistic_cdf.m, logistic_inv.m, logistic_pdf.m, logistic_rnd.m, logncdf.m, logninv.m, lognpdf.m, lognrnd.m, nbincdf.m, nbininv.m, nbinpdf.m, nbinrnd.m, normcdf.m, norminv.m, normpdf.m, normrnd.m, poisscdf.m, poissinv.m, poisspdf.m, poissrnd.m, stdnormal_cdf.m, stdnormal_inv.m, stdnormal_pdf.m, stdnormal_rnd.m, tcdf.m, tinv.m, tpdf.m, trnd.m, unidcdf.m, unidinv.m, unidpdf.m, unidrnd.m, unifcdf.m, unifinv.m, unifpdf.m, unifrnd.m, wblcdf.m, wblinv.m, wblpdf.m, wblrnd.m, kolmogorov_smirnov_test.m, kruskal_wallis_test.m, base2dec.m, bin2dec.m, blanks.m, cstrcat.m, deblank.m, dec2base.m, dec2bin.m, dec2hex.m, findstr.m, hex2dec.m, index.m, isletter.m, mat2str.m, rindex.m, str2num.m, strcat.m, strjust.m, strmatch.m, strsplit.m, strtok.m, strtrim.m, strtrunc.m, substr.m, validatestring.m, demo.m, example.m, fail.m, speed.m, addtodate.m, asctime.m, clock.m, ctime.m, date.m, datenum.m, datetick.m, datevec.m, eomday.m, etime.m, is_leap_year.m, now.m: Use Octave coding conventions in all m-file %!test blocks
author Rik <octave@nomad.inbox5.com>
date Mon, 13 Feb 2012 07:29:44 -0800
parents 72c96de7a403
children b7675598094a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13856
diff changeset
1 ## Copyright (C) 2000-2012 Paul Kienzle
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
2 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
4 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## your option) any later version.
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
9 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
14 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
18
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 9051
diff changeset
20 ## @deftypefn {Function File} {@var{v} =} datevec (@var{date})
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
21 ## @deftypefnx {Function File} {@var{v} =} datevec (@var{date}, @var{f})
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
22 ## @deftypefnx {Function File} {@var{v} =} datevec (@var{date}, @var{p})
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
23 ## @deftypefnx {Function File} {@var{v} =} datevec (@var{date}, @var{f}, @var{p})
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
24 ## @deftypefnx {Function File} {[@var{y}, @var{m}, @var{d}, @var{h}, @var{mi}, @var{s}] =} datevec (@dots{})
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
25 ## Convert a serial date number (see @code{datenum}) or date string (see
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
26 ## @code{datestr}) into a date vector.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
27 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
28 ## A date vector is a row vector with six members, representing the year,
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
29 ## month, day, hour, minute, and seconds respectively.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
30 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
31 ## @var{f} is the format string used to interpret date strings
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
32 ## (see @code{datestr}).
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
33 ##
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
34 ## @var{p} is the year at the start of the century to which two-digit years
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
35 ## will be referenced. If not specified, it defaults to the current year
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
36 ## minus 50.
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13848
diff changeset
37 ## @seealso{datenum, datestr, clock, now, date}
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
38 ## @end deftypefn
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
39
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
40 ## Algorithm: Peter Baum (http://vsg.cape.com/~pbaum/date/date0.htm)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
41
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
42 ## Author: pkienzle <pkienzle@users.sf.net>
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
43 ## Modified: bdenney <bill@givebillmoney.com>
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
44 ## Created: 10 October 2001 (CVS)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
45 ## Adapted-By: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com>
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
46
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
47 ## The function __date_str2vec__ is based on datesplit by Bill Denney.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
48
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
49 function [y, m, d, h, mi, s] = datevec (date, f = [], p = [])
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
50
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
51 persistent std_formats nfmt;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
52
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
53 if (isempty (std_formats))
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
54 std_formats = cell ();
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
55 nfmt = 0;
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
56 ## These formats are specified by Matlab to be parsed
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
57 ## The '# XX' refers to the datestr numerical format code
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
58 std_formats{++nfmt} = "dd-mmm-yyyy HH:MM:SS"; # 0
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
59 std_formats{++nfmt} = "dd-mmm-yyyy"; # 1
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
60 std_formats{++nfmt} = "mm/dd/yy"; # 2
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
61 std_formats{++nfmt} = "mm/dd"; # 6
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
62 std_formats{++nfmt} = "HH:MM:SS"; # 13
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
63 std_formats{++nfmt} = "HH:MM:SS PM"; # 14
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
64 std_formats{++nfmt} = "HH:MM"; # 15
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
65 std_formats{++nfmt} = "HH:MM PM"; # 16
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
66 std_formats{++nfmt} = "mm/dd/yyyy"; # 23
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
67
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
68 ## These are other formats that Octave tries
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
69 std_formats{++nfmt} = "mmm-dd-yyyy HH:MM:SS";
6044
12fd61d549ba [project @ 2006-10-09 21:28:23 by jwe]
jwe
parents: 5873
diff changeset
70 std_formats{++nfmt} = "mmm-dd-yyyy";
12fd61d549ba [project @ 2006-10-09 21:28:23 by jwe]
jwe
parents: 5873
diff changeset
71 std_formats{++nfmt} = "dd mmm yyyy HH:MM:SS";
12fd61d549ba [project @ 2006-10-09 21:28:23 by jwe]
jwe
parents: 5873
diff changeset
72 std_formats{++nfmt} = "dd mmm yyyy";
12fd61d549ba [project @ 2006-10-09 21:28:23 by jwe]
jwe
parents: 5873
diff changeset
73 std_formats{++nfmt} = "mmm dd yyyy HH:MM:SS";
12fd61d549ba [project @ 2006-10-09 21:28:23 by jwe]
jwe
parents: 5873
diff changeset
74 std_formats{++nfmt} = "mmm dd yyyy";
12fd61d549ba [project @ 2006-10-09 21:28:23 by jwe]
jwe
parents: 5873
diff changeset
75 std_formats{++nfmt} = "dd.mmm.yyyy HH:MM:SS";
12fd61d549ba [project @ 2006-10-09 21:28:23 by jwe]
jwe
parents: 5873
diff changeset
76 std_formats{++nfmt} = "dd.mmm.yyyy";
12fd61d549ba [project @ 2006-10-09 21:28:23 by jwe]
jwe
parents: 5873
diff changeset
77 std_formats{++nfmt} = "mmm.dd.yyyy HH:MM:SS";
12fd61d549ba [project @ 2006-10-09 21:28:23 by jwe]
jwe
parents: 5873
diff changeset
78 std_formats{++nfmt} = "mmm.dd.yyyy";
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
79 std_formats{++nfmt} = "mmmyy"; # 12
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
80 std_formats{++nfmt} = "mm/dd/yyyy HH:MM";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
81 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
82
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
83 if (nargin < 1 || nargin > 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 6044
diff changeset
84 print_usage ();
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
85 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
86
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
87 if (ischar (date))
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
88 date = cellstr (date);
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
89 endif
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
90
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
91 if (isnumeric (f))
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
92 p = f;
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
93 f = [];
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
94 endif
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
95
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
96 if (isempty (f))
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
97 f = -1;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
98 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
99
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
100 if (isempty (p))
11400
277d891afae2 datevec.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 11086
diff changeset
101 p = (localtime (time ())).year + 1900 - 50;
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
102 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
103
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
104 if (iscell (date))
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
105
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
106 nd = numel (date);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
107
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
108 y = m = d = h = mi = s = zeros (nd, 1);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
109
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
110 if (f == -1)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
111 for k = 1:nd
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
112 found = false;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
113 for l = 1:nfmt
8411
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
114 [f, rY, ry, fy, fm, fd, fh, fmi, fs] = __date_vfmt2sfmt__ (std_formats{l});
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
115 [found y(k) m(k) d(k) h(k) mi(k) s(k)] = __date_str2vec__ (date{k}, p, f, rY, ry, fy, fm, fd, fh, fmi, fs);
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
116 if (found)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
117 break;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
118 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
119 endfor
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
120 if (! found)
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11400
diff changeset
121 error ("datevec: none of the standard formats match the DATE string");
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
122 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
123 endfor
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
124 else
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
125 ## Decipher the format string just once for speed.
8411
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
126 [f, rY, ry, fy, fm, fd, fh, fmi, fs] = __date_vfmt2sfmt__ (f);
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
127 for k = 1:nd
8411
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
128 [found y(k) m(k) d(k) h(k) mi(k) s(k)] = __date_str2vec__ (date{k}, p, f, rY, ry, fy, fm, fd, fh, fmi, fs);
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
129 if (! found)
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11400
diff changeset
130 error ("datevec: DATE not parsed correctly with given format");
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
131 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
132 endfor
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
133 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
134
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
135 else # datenum input
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
136
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
137 date = date(:);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
138
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
139 ## Move day 0 from midnight -0001-12-31 to midnight 0000-3-1
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
140 z = floor (date) - 60;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
141 ## Calculate number of centuries; K1 = 0.25 is to avoid rounding problems.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
142 a = floor ((z - 0.25) / 36524.25);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
143 ## Days within century; K2 = 0.25 is to avoid rounding problems.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
144 b = z - 0.25 + a - floor (a / 4);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
145 ## Calculate the year (year starts on March 1).
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
146 y = floor (b / 365.25);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
147 ## Calculate day in year.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
148 c = fix (b - floor (365.25 * y)) + 1;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
149 ## Calculate month in year.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
150 m = fix ((5 * c + 456) / 153);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
151 d = c - fix ((153 * m - 457) / 5);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
152 ## Move to Jan 1 as start of year.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
153 ++y(m > 12);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
154 m(m > 12) -= 12;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
155
5859
ba0bea22167b [project @ 2006-06-14 18:18:51 by jwe]
jwe
parents: 5687
diff changeset
156 ## Convert hour-minute-seconds. Attempt to account for precision of
ba0bea22167b [project @ 2006-06-14 18:18:51 by jwe]
jwe
parents: 5687
diff changeset
157 ## datenum format.
ba0bea22167b [project @ 2006-06-14 18:18:51 by jwe]
jwe
parents: 5687
diff changeset
158
ba0bea22167b [project @ 2006-06-14 18:18:51 by jwe]
jwe
parents: 5687
diff changeset
159 fracd = date - floor (date);
5873
b6ef36e92701 [project @ 2006-06-30 20:46:34 by jwe]
jwe
parents: 5860
diff changeset
160 tmps = abs (eps*86400*date);
b6ef36e92701 [project @ 2006-06-30 20:46:34 by jwe]
jwe
parents: 5860
diff changeset
161 tmps(tmps == 0) = 1;
b6ef36e92701 [project @ 2006-06-30 20:46:34 by jwe]
jwe
parents: 5860
diff changeset
162 srnd = 2 .^ floor (- log2 (tmps));
b6ef36e92701 [project @ 2006-06-30 20:46:34 by jwe]
jwe
parents: 5860
diff changeset
163 s = round (86400 * fracd .* srnd) ./ srnd;
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
164 h = floor (s / 3600);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
165 s = s - 3600 * h;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
166 mi = floor (s / 60);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
167 s = s - 60 * mi;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
168
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
169 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
170
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
171 if (nargout <= 1)
5873
b6ef36e92701 [project @ 2006-06-30 20:46:34 by jwe]
jwe
parents: 5860
diff changeset
172 y = [y, m, d, h, mi, s];
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
173 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
174
11086
af03ff97df7b datevec.m: use endfunction to mark end of primary function and subfunctions
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
175 endfunction
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
176
8411
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
177 function [f, rY, ry, fy, fm, fd, fh, fmi, fs] = __date_vfmt2sfmt__ (f)
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
178
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8411
diff changeset
179 ## Play safe with percent signs.
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
180 f = strrep (f, "%", "%%");
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
181
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
182 if (! isempty (strfind (f, "PM")) || ! isempty (strfind (f, "AM")))
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
183 ampm = true;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
184 else
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
185 ampm = false;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
186 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
187
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8411
diff changeset
188 ## Date part.
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
189 f = regexprep (f, '[Yy][Yy][Yy][Yy]', "%Y");
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
190 f = regexprep (f, '[Yy][Yy]', "%y");
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
191 f = strrep (f, "mmmm", "%B");
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
192 f = strrep (f, "mmm", "%b");
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
193 f = strrep (f, "mm", "%m");
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
194 f = regexprep (f, '[Dd][Dd][Dd][Dd]', "%A");
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
195 f = regexprep (f, '[Dd][Dd][Dd]', "%a");
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
196 f = regexprep (f, '[Dd][Dd]', "%d");
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
197
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8411
diff changeset
198 ## Time part.
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
199 if (ampm)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
200 f = strrep (f, "HH", "%I");
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
201 f = strrep (f, "PM", "%p");
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
202 f = strrep (f, "AM", "%p");
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
203 else
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
204 f = strrep (f, "HH", "%H");
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
205 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
206 f = strrep (f, "MM", "%M");
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
207 f = regexprep (f, '[Ss][Ss]', "%S");
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
208
8411
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
209 rY = rindex (f, "%Y");
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
210 ry = rindex (f, "%y");
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
211
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8411
diff changeset
212 ## Check whether we need to give default values.
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8411
diff changeset
213 ## Possible error when string contains "%%".
8411
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
214 fy = rY || ry;
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
215 fm = index (f, "%m") || index (f, "%b") || index (f, "%B");
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
216 fd = index (f, "%d") || index (f, "%a") || index (f, "%A");
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
217 fh = index (f, "%H") || index (f, "%I");
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
218 fmi = index (f, "%M");
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
219 fs = index (f, "%S");
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
220
11086
af03ff97df7b datevec.m: use endfunction to mark end of primary function and subfunctions
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
221 endfunction
8411
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
222
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
223 function [found, y, m, d, h, mi, s] = __date_str2vec__ (ds, p, f, rY, ry, fy, fm, fd, fh, fmi, fs)
69d45a4c7d94 avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 7044
diff changeset
224
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
225 idx = strfind (f, "FFF");
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
226 if (! isempty (idx))
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
227 ## Kludge to handle FFF millisecond format since strptime does not
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
228 f(idx:idx+2) = [];
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
229 [~, nc] = strptime (ds, f);
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
230 if (nc > 0)
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
231 msec = ds(nc:min(nc+2, end));
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
232 f = [f(1:idx-1) msec f(idx:end)];
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
233 [tm, nc] = strptime (ds, f);
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
234 tm.usec = 1000 * str2double (msec);
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
235 endif
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
236 else
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
237 [tm, nc] = strptime (ds, f);
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
238 endif
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
239
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
240 if (nc == columns (ds) + 1)
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
241 found = true;
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
242 y = tm.year + 1900; m = tm.mon + 1; d = tm.mday;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
243 h = tm.hour; mi = tm.min; s = tm.sec + tm.usec / 1e6;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
244 if (rY < ry)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
245 if (y > 1999)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
246 y -= 2000;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
247 else
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
248 y -= 1900;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
249 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
250 y += p - mod (p, 100);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
251 if (y < p)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
252 y += 100;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
253 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
254 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
255 if (! fy && ! fm && ! fd)
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8411
diff changeset
256 tmp = localtime (time ());
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8411
diff changeset
257 y = tmp.year + 1900;
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8411
diff changeset
258 m = tmp.mon + 1;
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8411
diff changeset
259 d = tmp.mday;
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
260 elseif (! fy && fm && fd)
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8411
diff changeset
261 tmp = localtime (time ());
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8411
diff changeset
262 y = tmp.year + 1900;
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
263 elseif (fy && fm && ! fd)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
264 d = 1;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
265 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
266 if (! fh && ! fmi && ! fs)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
267 h = mi = s = 0;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
268 elseif (fh && fmi && ! fs)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
269 s = 0;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
270 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
271 else
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
272 y = m = d = h = mi = s = 0;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
273 found = false;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
274 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
275
11086
af03ff97df7b datevec.m: use endfunction to mark end of primary function and subfunctions
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
276 endfunction
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
277
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
278
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
279 %!demo
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
280 %! ## Current date and time
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
281 %! datevec (now ())
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
282
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
283 %!shared nowvec
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
284 %! nowvec = datevec (now); # Some tests could fail around midnight!
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
285 %!# tests for standard formats: 0, 1, 2, 6, 13, 14, 15, 16, 23
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
286 %!assert (datevec ("07-Sep-2000 15:38:09"), [2000,9,7,15,38,9])
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
287 %!assert (datevec ("07-Sep-2000"), [2000,9,7,0,0,0])
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
288 %!assert (datevec ("09/07/00"), [2000,9,7,0,0,0])
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
289 %!assert (datevec ("09/13"), [nowvec(1),9,13,0,0,0])
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
290 %!assert (datevec ("15:38:09"), [nowvec(1:3),15,38,9])
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
291 %!assert (datevec ("3:38:09 PM"), [nowvec(1:3),15,38,9])
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
292 %!assert (datevec ("15:38"), [nowvec(1:3),15,38,0])
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
293 %!assert (datevec ("03:38 PM"), [nowvec(1:3),15,38,0])
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
294 %!assert (datevec ("03/13/1962"), [1962,3,13,0,0,0])
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
295
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
296 %% Test millisecond format FFF
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
297 %!assert (datevec ("15:38:21.25", "HH:MM:SS.FFF"), [nowvec(1:3),15,38,21.025])
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
298
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
299 # Other tests
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
300 %!assert (datenum (datevec ([-1e4:1e4])), [-1e4:1e4]');
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
301 %!test
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
302 %! t = linspace (-2e5, 2e5, 10993);
5860
b645066d40ad [project @ 2006-06-16 05:01:38 by jwe]
jwe
parents: 5859
diff changeset
303 %! assert (all (abs (datenum (datevec (t)) - t') < 1e-5));
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
304