summaryrefslogtreecommitdiff
path: root/libpurple/util.c
diff options
context:
space:
mode:
authorGary Kramlich <grim@reaperworld.com>2022-01-13 23:47:42 -0600
committerGary Kramlich <grim@reaperworld.com>2022-01-13 23:47:42 -0600
commit35688def2db6843f467bfb5ff632effd8a253657 (patch)
tree38d27885e6870f23ecd5d61d2d5bf8b1e700101e /libpurple/util.c
parent15cc4e9de52b40c43261e68faebe67ff3a25e09f (diff)
downloadpidgin-35688def2db6843f467bfb5ff632effd8a253657.tar.gz
remove purple_str_to_time and other unused time utility functions
Testing Done: Compiled, ran tests, and ran the program. Reviewed at https://reviews.imfreedom.org/r/1226/
Diffstat (limited to 'libpurple/util.c')
-rw-r--r--libpurple/util.c348
1 files changed, 0 insertions, 348 deletions
diff --git a/libpurple/util.c b/libpurple/util.c
index 24a6e6fe26..e28ee036e6 100644
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -87,354 +87,6 @@ purple_date_format_full(const struct tm *tm)
return purple_utf8_strftime("%c", tm);
}
-/* originally taken from GLib trunk 1-6-11 */
-/* originally licensed as LGPL 2+ */
-static time_t
-mktime_utc(struct tm *tm)
-{
- time_t retval;
-
-#ifndef HAVE_TIMEGM
- static const gint days_before[] =
- {
- 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
- };
-#endif
-
-#ifndef HAVE_TIMEGM
- if (tm->tm_mon < 0 || tm->tm_mon > 11)
- return (time_t) -1;
-
- retval = (tm->tm_year - 70) * 365;
- retval += (tm->tm_year - 68) / 4;
- retval += days_before[tm->tm_mon] + tm->tm_mday - 1;
-
- if (tm->tm_year % 4 == 0 && tm->tm_mon < 2)
- retval -= 1;
-
- retval = ((((retval * 24) + tm->tm_hour) * 60) + tm->tm_min) * 60 + tm->tm_sec;
-#else
- retval = timegm (tm);
-#endif /* !HAVE_TIMEGM */
-
- return retval;
-}
-
-time_t
-purple_str_to_time(const char *timestamp, gboolean utc,
- struct tm *tm, long *tz_off, const char **rest)
-{
- struct tm t;
- const gchar *str;
- gint year = 0;
- long tzoff = PURPLE_NO_TZ_OFF;
- time_t retval;
- gboolean mktime_with_utc = FALSE;
-
- if (rest != NULL)
- *rest = NULL;
-
- g_return_val_if_fail(timestamp != NULL, 0);
-
- memset(&t, 0, sizeof(struct tm));
-
- str = timestamp;
-
- /* Strip leading whitespace */
- while (g_ascii_isspace(*str))
- str++;
-
- if (*str == '\0') {
- if (rest != NULL) {
- *rest = str;
- }
-
- return 0;
- }
-
- if (!g_ascii_isdigit(*str) && *str != '-' && *str != '+') {
- if (rest != NULL && *str != '\0')
- *rest = str;
-
- return 0;
- }
-
- /* 4 digit year */
- if (sscanf(str, "%04d", &year) && year >= 1900) {
- str += 4;
-
- if (*str == '-' || *str == '/')
- str++;
-
- t.tm_year = year - 1900;
- }
-
- /* 2 digit month */
- if (!sscanf(str, "%02d", &t.tm_mon)) {
- if (rest != NULL && *str != '\0')
- *rest = str;
-
- return 0;
- }
-
- str += 2;
- t.tm_mon -= 1;
-
- if (*str == '-' || *str == '/')
- str++;
-
- /* 2 digit day */
- if (!sscanf(str, "%02d", &t.tm_mday)) {
- if (rest != NULL && *str != '\0')
- *rest = str;
-
- return 0;
- }
-
- str += 2;
-
- /* Grab the year off the end if there's still stuff */
- if (*str == '/' || *str == '-') {
- /* But make sure we don't read the year twice */
- if (year >= 1900) {
- if (rest != NULL && *str != '\0')
- *rest = str;
-
- return 0;
- }
-
- str++;
-
- if (!sscanf(str, "%04d", &t.tm_year)) {
- if (rest != NULL && *str != '\0')
- *rest = str;
-
- return 0;
- }
-
- t.tm_year -= 1900;
- } else if (*str == 'T' || *str == '.') {
- str++;
-
- /* Continue grabbing the hours/minutes/seconds */
- if ((sscanf(str, "%02d:%02d:%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3 &&
- (str += 8)) ||
- (sscanf(str, "%02d%02d%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3 &&
- (str += 6)))
- {
- gint sign, tzhrs, tzmins;
-
- if (*str == '.') {
- /* Cut off those pesky micro-seconds */
- do {
- str++;
- } while (*str >= '0' && *str <= '9');
- }
-
- sign = (*str == '+') ? 1 : -1;
-
- /* Process the timezone */
- if (*str == '+' || *str == '-') {
- str++;
-
- if (((sscanf(str, "%02d:%02d", &tzhrs, &tzmins) == 2 && (str += 5)) ||
- (sscanf(str, "%02d%02d", &tzhrs, &tzmins) == 2 && (str += 4))))
- {
- mktime_with_utc = TRUE;
- tzoff = tzhrs * 60 * 60 + tzmins * 60;
- tzoff *= sign;
- }
- } else if (*str == 'Z') {
- /* 'Z' = Zulu = UTC */
- str++;
- mktime_with_utc = TRUE;
- tzoff = 0;
- }
-
- if (!mktime_with_utc)
- {
- /* No timezone specified. */
-
- if (utc) {
- mktime_with_utc = TRUE;
- tzoff = 0;
- } else {
- /* Local Time */
- t.tm_isdst = -1;
- }
- }
- }
- }
-
- if (rest != NULL && *str != '\0') {
- /* Strip trailing whitespace */
- while (g_ascii_isspace(*str))
- str++;
-
- if (*str != '\0')
- *rest = str;
- }
-
- if (mktime_with_utc)
- retval = mktime_utc(&t);
- else
- retval = mktime(&t);
-
- if (tm != NULL)
- *tm = t;
-
- if (tzoff != PURPLE_NO_TZ_OFF)
- retval -= tzoff;
-
- if (tz_off != NULL)
- *tz_off = tzoff;
-
- return retval;
-}
-
-GDateTime *
-purple_str_to_date_time(const char *timestamp, gboolean utc)
-{
- const gchar *str;
- gint year = 0;
- gint month = 0;
- gint day = 0;
- gint hour = 0;
- gint minute = 0;
- gint seconds = 0;
- gint microseconds = 0;
- int chars = 0;
- GTimeZone *tz = NULL;
- GDateTime *retval;
-
- g_return_val_if_fail(timestamp != NULL, NULL);
-
- str = timestamp;
-
- /* Strip leading whitespace */
- while (g_ascii_isspace(*str))
- str++;
-
- if (*str == '\0') {
- return NULL;
- }
-
- if (!g_ascii_isdigit(*str) && *str != '-' && *str != '+') {
- return NULL;
- }
-
- /* 4 digit year */
- if (sscanf(str, "%04d", &year) && year > 0) {
- str += 4;
-
- if (*str == '-' || *str == '/')
- str++;
- }
-
- /* 2 digit month */
- if (!sscanf(str, "%02d", &month)) {
- return NULL;
- }
-
- str += 2;
-
- if (*str == '-' || *str == '/')
- str++;
-
- /* 2 digit day */
- if (!sscanf(str, "%02d", &day)) {
- return NULL;
- }
-
- str += 2;
-
- /* Grab the year off the end if there's still stuff */
- if (*str == '/' || *str == '-') {
- /* But make sure we don't read the year twice */
- if (year > 0) {
- return NULL;
- }
-
- str++;
-
- if (!sscanf(str, "%04d", &year)) {
- return NULL;
- }
- } else if (*str == 'T' || *str == '.') {
- str++;
-
- /* Continue grabbing the hours/minutes/seconds */
- if ((sscanf(str, "%02d:%02d:%02d", &hour, &minute, &seconds) == 3 &&
- (str += 8)) ||
- (sscanf(str, "%02d%02d%02d", &hour, &minute, &seconds) == 3 &&
- (str += 6)))
- {
- if (*str == '.') {
- str++;
- if (sscanf(str, "%d%n", &microseconds, &chars) == 1) {
- str += chars;
- }
- }
-
- if (*str) {
- const gchar *end = str;
- if (*end == '+' || *end == '-') {
- end++;
- }
-
- while (isdigit(*end) || *end == ':') {
- end++;
- }
-
- if (str != end) {
- /* Trim anything trailing a purely numeric time zone. */
- gchar *tzstr = g_strndup(str, end - str);
- tz = g_time_zone_new_identifier(tzstr);
- g_free(tzstr);
- if (tz == NULL) {
- tz = g_time_zone_new_identifier("UTC");
- }
- } else {
- /* Just try whatever is there. */
- tz = g_time_zone_new_identifier(str);
- if (tz == NULL) {
- tz = g_time_zone_new_identifier("UTC");
- }
- }
- }
- }
- }
-
- if (!tz) {
- /* No timezone specified. */
- if (utc) {
- tz = g_time_zone_new_utc();
- } else {
- tz = g_time_zone_new_local();
- }
- }
-
- retval = g_date_time_new(tz, year, month, day, hour, minute,
- seconds + microseconds * pow(10, -chars));
- g_time_zone_unref(tz);
-
- return retval;
-}
-
-gint purple_time_parse_month(const char *month_abbr)
-{
- const char *months[] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
- NULL};
- for (gint month = 0; months[month] != NULL; month++) {
- if (purple_strequal(month_abbr, months[month])) {
- return month + 1;
- }
- }
- return 0;
-}
-
/**************************************************************************
* Path/Filename Functions
**************************************************************************/