libpurple/util.c

changeset 41249
b147a2ac58f0
parent 41237
5098e0dd3a09
child 41250
e82d07ed6862
--- a/libpurple/util.c	Thu Jan 13 23:13:13 2022 -0600
+++ b/libpurple/util.c	Thu Jan 13 23:47:42 2022 -0600
@@ -87,354 +87,6 @@
 	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
  **************************************************************************/

mercurial