View Raw SPL
/*****************************************************************************
* *
* YMD2DATE.SPL Copyright (C) 2024 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Converts a series to Julian dates *
* *
* Revisions: 2 Dec 2024 RRR Creation *
* *
*****************************************************************************/
#if @HELP_YMD2DATE
YMD2DATE
Purpose: Converts series of years, months and day values to Julian dates
Syntax: YMD2DATE(years, months, days)
years - A scalar or series, the year values.
months - A scalar or series, the month values.
days - A scalar or series, the day values.
Returns: A series or array of Julian integers.
Example:
W1: ymd2date(2030, 10, 31)
W1 contains the date 10/31/2030 with the equivalent Julian
day value of 2462806.
Example:
W1: {1998, 1999, 2000}
W2: {1, 1, 1}
W3: {10, 11, 15}
W4: ymd2date(w1, w2, w3)
W1 contains the year values.
W2 contains the month values.
W3 contains the day values.
W4 contains the date series:
1-10-1998
1-11-1999
1-15-2000
Example:
W1: ymd2date(1998..2000, 1, {10, 11, 15})
Same as above except the year, month and day values are entered
directly as series.
W1 contains the date series:
1-10-1998
1-11-1999
1-15-2000
Example:
W1: ymd2date(1998..2000, 1, {10, 11, 45})
Same as above except the last day value of 45 causes the
resulting month to rollover.
W1 contains the date series:
1-10-1998
1-11-1999
2-14-2000
Remarks:
YMD2DATE creates a date series by combining individual year,
month and day values.
Out of range month and day values are rolled over.
See YMDHMS2DT to convert years, months, days, hours, minutes
and seconds to a date time series.
See Also:
DATE2YMD
JULSTR
JULYMD
YMDHMS2DT
#endif
/* year, month, day to Julian date */
ymd2date(years = 0, months = 1, days = 1)
{
local date = {};
if (argc <= 1)
{
if (argc < 1)
{
/* current date */
years = getdate();
}
if (isdatestr(years))
{
/* convert date string - force series */
date = {julstr(years)};
setvunits(date, "Date");
}
else if (isstring(years))
{
error(sprintf("%s - unrecognized date '%s'", __FUNC__, years));
}
else if (years <= 0)
{
years = getdate();
}
}
if (isempty(date))
{
/* parse components to series */
(years, months, days) = d_or_t_2_parse_args(argc, years, months, days);
/* internal conversion */
date = julfromymd(years, months, days);
}
/* tabular view */
settable(date);
return(date);
}