IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17023


Ignore:
Timestamp:
Mar 17, 2008, 1:53:59 PM (18 years ago)
Author:
eugene
Message:

add psTimeFromString to parse various human-readable formats

Location:
trunk/psLib/src/astro
Files:
2 edited

Legend:

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

    r14077 r17023  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.114 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2007-07-09 20:11:29 $
     12 *  @version $Revision: 1.115 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2008-03-17 23:53:43 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    15451545}
    15461546
     1547// accepts a range of human readable times:
     1548// ISO (YYYY-MM-MMTHH:MM:SS[.sss][Z])
     1549// YYYY/MM/DD,HH:MM:DD
     1550psTime* psTimeFromString(const char *input,
     1551                      psTimeType type)
     1552{
     1553
     1554    // Check for NULL string
     1555    PS_ASSERT_PTR_NON_NULL(input,NULL);
     1556    PS_ASSERT_INT_WITHIN_RANGE(type, PS_TIME_TAI, PS_TIME_TT, NULL);
     1557
     1558    psTime *outTime = NULL;
     1559
     1560    // Convert YYYY-MM-DDThh:mm:ss.sss[Z] in string form to tm time
     1561    outTime = psTimeStrptime(input, "%Y-%m-%dT%H:%M:%S");
     1562    if (outTime) {
     1563      outTime->type = type;
     1564      return outTime;
     1565    }
     1566    psErrorClear ();
     1567
     1568    // Convert YYYY/MM/DD,hh:mm:ss.sss[Z] in string form to tm time
     1569    outTime = psTimeStrptime(input, "%Y/%m/%d,%H:%M:%S");
     1570    if (outTime) {
     1571      outTime->type = type;
     1572      return outTime;
     1573    }
     1574    psErrorClear ();
     1575
     1576    // Convert YYYY/MM/DD@hh:mm:ss.sss[Z] in string form to tm time
     1577    outTime = psTimeStrptime(input, "%Y/%m/%d@%H:%M:%S");
     1578    if (outTime) {
     1579      outTime->type = type;
     1580      return outTime;
     1581    }
     1582    psErrorClear ();
     1583
     1584    // try for date with assumed 00:00:00 time
     1585    outTime = psTimeStrptime(input, "%Y-%m-%d");
     1586    if (outTime) {
     1587      outTime->type = type;
     1588      return outTime;
     1589    }
     1590    psErrorClear ();
     1591
     1592    // try for date with assumed 00:00:00 time
     1593    outTime = psTimeStrptime(input, "%Y/%m/%d");
     1594    if (outTime) {
     1595      outTime->type = type;
     1596      return outTime;
     1597    }
     1598    psErrorClear ();
     1599
     1600    psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified Time string, '%s', is malformed.  Must be in 'YYYY-MM-DDThh:mm:ss.sss' format."), input);
     1601    return NULL;
     1602}
     1603
    15471604psTime* psTimeFromTT(psS64 sec,
    15481605                     psU32 nsec)
  • trunk/psLib/src/astro/psTime.h

    r14452 r17023  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.57 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2007-08-09 01:40:07 $
     13 *  @version $Revision: 1.58 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2008-03-17 23:53:59 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    315315);
    316316
     317/** Convert various human-readable formats to psTime.
     318 *
     319 *  Converts human readable time formats to psTime. This function does not add or subtract leapseconds.
     320 *
     321 *  @return  psTime*: time
     322 */
     323psTime* psTimeFromString(
     324    const char* input,                 ///< Input time to be converted.
     325    psTimeType type                    ///< Time type.
     326);
     327
    317328/** Convert timeval to psTime.
    318329 *
Note: See TracChangeset for help on using the changeset viewer.