IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 10736


Ignore:
Timestamp:
Dec 14, 2006, 1:02:46 PM (20 years ago)
Author:
magnier
Message:

two fixes: catch fractional seconds in psTimeStrptime, allow YYYY-MM-DD with implied 00:00:00 in psTimeFromISO

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/astro/psTime.c

    r10122 r10736  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.106 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2006-11-21 19:23:02 $
     12 *  @version $Revision: 1.107 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-12-14 23:02:46 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2525#include "psError.h"
    2626#include "psLogMsg.h"
     27#include "psTrace.h"
    2728#include "psMemory.h"
    2829#include "psAbort.h"
     
    14981499    psTime *outTime = psTimeStrptime(input, "%Y-%m-%dT%H:%M:%S");
    14991500    if (!outTime) {
    1500         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified ISO Time string, '%s', is malformed.  Must be in 'YYYY-MM-DDThh:mm:ss.sss' format."), input);
    1501         return NULL;
     1501        // try for date with assumed 00:00:00 time
     1502        outTime = psTimeStrptime(input, "%Y-%m-%d");
     1503        if (!outTime) {
     1504            psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified ISO Time string, '%s', is malformed.  Must be in 'YYYY-MM-DDThh:mm:ss.sss' format."), input);
     1505            return NULL;
     1506        }
    15021507    }
    15031508
     
    16401645    PS_ASSERT_PTR_NON_NULL(format, NULL);
    16411646
     1647    double fractionalSeconds = 0.0;
     1648
    16421649    struct tm tmTime;
     1650    tmTime.tm_year = tmTime.tm_mon = tmTime.tm_mday = 0;
     1651    tmTime.tm_hour = tmTime.tm_min = tmTime.tm_sec = 0;
    16431652    char *lastChar = strptime(s, format, &tmTime);
    16441653    if (!lastChar) {
     
    16481657
    16491658    if (*lastChar != '\0') {
    1650         psWarning("time string was not completely consumed\n");
     1659        psTrace("psLib.astrom", 3, "handling fractional second in time string\n");
     1660        // XXXXXXXXXXXXXXX
     1661        // XXX this is a really stupid error:
     1662        // we are dropping the fractional seconds with this conversion
     1663        // I've put in a proposed fix, but PLEASE test!!!
     1664        if (*lastChar == '.') {
     1665            char *reallyLast;
     1666            fractionalSeconds = strtod (lastChar, &reallyLast);
     1667            if (!reallyLast) {
     1668                psWarning("time string was not completely consumed\n");
     1669            }
     1670        }
    16511671    }
    16521672
     
    16571677    }
    16581678
     1679    time->nsec += fractionalSeconds * 1e9;
    16591680    return time;
    16601681}
Note: See TracChangeset for help on using the changeset viewer.