static SoupDate* msToSoupDate(double ms) { int year = msToYear(ms); int dayOfYear = dayInYear(ms, year); bool leapYear = isLeapYear(year); return soup_date_new(year, monthFromDayInYear(dayOfYear, leapYear), dayInMonthFromDayInYear(dayOfYear, leapYear), msToHours(ms), msToMinutes(ms), static_cast<int>(ms / 1000) % 60); }
/** * soup_date_new_from_time_t: * @when: a #time_t * * Creates a #SoupDate corresponding to @when * * Return value: a new #SoupDate **/ SoupDate * soup_date_new_from_time_t (time_t when) { struct tm tm; #ifdef HAVE_GMTIME_R gmtime_r (&when, &tm); #else tm = *gmtime (&when); #endif return soup_date_new (tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); }
static gboolean test_dateChange (void) { GHashTable *structval; SoupDate *date, *result; char *timestamp; GValue retval; gboolean ok; debug_printf (1, "dateChange (date, struct of ints -> time): "); date = soup_date_new (1970 + (rand () % 50), 1 + rand () % 12, 1 + rand () % 28, rand () % 24, rand () % 60, rand () % 60); if (debug_level >= 2) { timestamp = soup_date_to_string (date, SOUP_DATE_ISO8601_XMLRPC); debug_printf (2, "date: %s, {", timestamp); g_free (timestamp); } structval = soup_value_hash_new (); if (rand () % 3) { date->year = 1970 + (rand () % 50); debug_printf (2, "tm_year: %d, ", date->year - 1900); soup_value_hash_insert (structval, "tm_year", G_TYPE_INT, date->year - 1900); } if (rand () % 3) { date->month = 1 + rand () % 12; debug_printf (2, "tm_mon: %d, ", date->month - 1); soup_value_hash_insert (structval, "tm_mon", G_TYPE_INT, date->month - 1); } if (rand () % 3) { date->day = 1 + rand () % 28; debug_printf (2, "tm_mday: %d, ", date->day); soup_value_hash_insert (structval, "tm_mday", G_TYPE_INT, date->day); } if (rand () % 3) { date->hour = rand () % 24; debug_printf (2, "tm_hour: %d, ", date->hour); soup_value_hash_insert (structval, "tm_hour", G_TYPE_INT, date->hour); } if (rand () % 3) { date->minute = rand () % 60; debug_printf (2, "tm_min: %d, ", date->minute); soup_value_hash_insert (structval, "tm_min", G_TYPE_INT, date->minute); } if (rand () % 3) { date->second = rand () % 60; debug_printf (2, "tm_sec: %d, ", date->second); soup_value_hash_insert (structval, "tm_sec", G_TYPE_INT, date->second); } debug_printf (2, "} -> "); ok = (do_xmlrpc ("dateChange", &retval, SOUP_TYPE_DATE, date, G_TYPE_HASH_TABLE, structval, G_TYPE_INVALID) && check_xmlrpc (&retval, SOUP_TYPE_DATE, &result)); g_hash_table_destroy (structval); if (!ok) { soup_date_free (date); return FALSE; } if (debug_level >= 2) { timestamp = soup_date_to_string (result, SOUP_DATE_ISO8601_XMLRPC); debug_printf (2, "%s: ", timestamp); g_free (timestamp); } ok = ((date->year == result->year) && (date->month == result->month) && (date->day == result->day) && (date->hour == result->hour) && (date->minute == result->minute) && (date->second == result->second)); soup_date_free (date); soup_date_free (result); debug_printf (1, "%s\n", ok ? "OK!" : "WRONG!"); return ok; }