Beispiel #1
0
int date_parse_iso (struct universaltime *ut, Octstr *os)
{
    long pos = 0;
    int c;

    /* assign defaults */
    ut->month = 0;
    ut->day = 1;
    ut->hour = 0;
    ut->minute = 0;
    ut->second = 0;

    if ((pos = octstr_parse_long(&(ut->year), os, pos, 10)) < 0)
        return -1;
    if (ut->year < 70)
        ut->year += 2000;
    else if (ut->year < 100)
	ut->year += 1900;

    while ((c = octstr_get_char(os, pos)) != -1 && !gw_isdigit(c))
	pos++;
    if ((pos = octstr_parse_long(&(ut->month), os, pos, 10)) < 0)
	return 0;

    /* 0-based months */
    if (ut->month > 0)
        ut->month--;

    while ((c = octstr_get_char(os, pos)) != -1 && !gw_isdigit(c))
        pos++;
    if ((pos = octstr_parse_long(&(ut->day), os, pos, 10)) < 0)
	return 0;

    while ((c = octstr_get_char(os, pos)) != -1 && !gw_isdigit(c))
        pos++;
    if ((pos = octstr_parse_long(&(ut->hour), os, pos, 10)) < 0)
	return 0;

    while ((c = octstr_get_char(os, pos)) != -1 && !gw_isdigit(c))
        pos++;
    if ((pos = octstr_parse_long(&(ut->minute), os, pos, 10)) < 0)
	return 0;

    while ((c = octstr_get_char(os, pos)) != -1 && !gw_isdigit(c))
        pos++;
    if ((pos = octstr_parse_long(&(ut->second), os, pos, 10)) < 0)
	return 0;

    return 0;
}
Beispiel #2
0
int date_parse_iso (struct universaltime *ut, Octstr *os)
{
    int n = 0;
    char *p, *q;

    /* assign defaults */
    ut->month = 0;
    ut->day = 1;
    ut->hour = 0;
    ut->minute = 0;
    ut->second = 0;

    p = octstr_get_cstr(os);
    q = p + ((n = octstr_search_char(os, 'T', 0)) >= 0 ? n : octstr_len(os)); /* stop at the end of string or at the time separator */
    if (sscanf(p, "%4ld%n", &ut->year, &n) < 1)
        return -1;
    p += n;

    if (ut->year < 70)
        ut->year += 2000;
    else if (ut->year < 100)
	ut->year += 1900;
     
    while (p < q && !gw_isdigit(*p))
	p++;     
    if (sscanf(p, "%2ld%n", &ut->month, &n) < 1)
	return 0;
    p += n;
     
     /* 0-based months */
    if (ut->month > 0)
	ut->month--;
     
    while (p < q && !gw_isdigit(*p))
        p++;     
    if (sscanf(p, "%2ld%n", &ut->day, &n) < 1)
	return 0;
    p += n;

    if (*q == 'T') 
	p = q+1;
    else
        return 0;

    while (*p && !gw_isdigit(*p))
	p++;     
    if (sscanf(p, "%2ld%n", &ut->hour, &n) < 1)
	return 0;
    p += n;

    while (*p && !gw_isdigit(*p))
	p++;     
    if (sscanf(p, "%2ld%n", &ut->minute, &n) < 1)
	return 0;
    p += n;
     
    while (*p && !gw_isdigit(*p))
	p++;     
    if (sscanf(p, "%2ld%n", &ut->second, &n) < 1)
	return 0;
     p += n;

    return 0;
}