View Raw SPL
/****************************************************************************
*                                                                           *
*   DECTIME.SPL Copyright 2007 (C) DSP Development Corporation              *
*                                                                           *
*   Author:     Randy Race                                                  *
*                                                                           *
*   Synopsis:   Converts decimal days (127) to a date (7-7-07)              *
*                                                                           *
*   Revisions:   8 Nov 2007     RRR     Creation                            *
*                                                                           *
****************************************************************************/

#include 

#if @HELP_DECDATE

    DECDATE

    Purpose: Converts decimal days to julian date data

    Syntax:  DECDATE(d, date)

                 d - A series of decimal date values where
                     d represents the day of the year.

              date - Optional string, the starting date. Defaults
                     to the date of d.

    Returns: A series of date values.

    Example:
             W1: {10, 100, 200, 300}
             W2: decdate(w1, "1-1-2010")

             W2 contains the date values:

             1/10/10  4/10/10  7/19/10  10/27/10

    Remarks:
             A decimal date value is an integer indicating the day
             of the year such that the value 1 represents the first
             day.

             Only the year portion of the date string or series date is
             used to set the starting year.

    See Also:
             DECTIME
             DTXY
             JULSTR
             STRJUL
             STRTOD
             TODSTR
             XYDT
#endif


/* convert decimal date to our date */
decdate(d, date)
{
        local juldate, year;

        if (argc < 2)
        {
                if (argc < 1) error("decdate - input series required");
                
                date = getdate(d);
        }

        /* extract year from date string */
        year = castint(strjul(julstr(date), 7));

        /* create 1-1-year date string */
        date = sprintf("1-1-%d", year);

        /* add julian date offset to day data */
        juldate = julstr(date) + d - 1;

        /* set units */
        setvunits(juldate, "Daily");
        
        return(juldate);
}