aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/cal-util/timeutil.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@helixcode.com>2000-12-20 02:12:57 +0800
committerFederico Mena Quintero <federico@src.gnome.org>2000-12-20 02:12:57 +0800
commitde861766eded0c80ffbe050088043a16d7e4923f (patch)
tree5010fda36af306efaab59e11ebfa12b7bd43023a /calendar/cal-util/timeutil.c
parent20dabfff3014eb67b5c930345e8cb64116dba374 (diff)
downloadgsoc2013-evolution-de861766eded0c80ffbe050088043a16d7e4923f.tar
gsoc2013-evolution-de861766eded0c80ffbe050088043a16d7e4923f.tar.gz
gsoc2013-evolution-de861766eded0c80ffbe050088043a16d7e4923f.tar.bz2
gsoc2013-evolution-de861766eded0c80ffbe050088043a16d7e4923f.tar.lz
gsoc2013-evolution-de861766eded0c80ffbe050088043a16d7e4923f.tar.xz
gsoc2013-evolution-de861766eded0c80ffbe050088043a16d7e4923f.tar.zst
gsoc2013-evolution-de861766eded0c80ffbe050088043a16d7e4923f.zip
Fix confusion in the way the range is expanded.
2000-12-19 Federico Mena Quintero <federico@helixcode.com> * pcs/cal-backend-file.c (compute_alarm_range): Fix confusion in the way the range is expanded. * cal-util/cal-component.c (cal_component_alarms_free): Doh, alarms->alarms is a list, not a generic pointer. Free it properly. (cal_component_free_pilot_id): Removed unused function. (cal_component_free_pilot_status): Likewise. * gui/main.c (init_bonobo): Use VERSION instead of a hardcoded string. Pass argc by value, not by reference. Test the return value of gnome_init_with_popt_table(). * cal-client/cal-client.c (cal_client_free_alarms): Oops, missed implementing this function. * cal-util/timeutil.c (print_time_t): Better printing format. (isodiff_to_secs): Removed unused function. (isodiff_from_secs): Removed unused function. (time_day_end): Removed crufty part. (time_day_begin): Removed crufty part. (time_day_hour): Removed unused function. (format_simple_hour): Removed unused function. (get_time_t_hour): Removed unused function. (time_from_start_duration): Removed unused function. * cal-util/timeutil.h (parse_date): Removed unimplemented, unused function prototype. svn path=/trunk/; revision=7083
Diffstat (limited to 'calendar/cal-util/timeutil.c')
-rw-r--r--calendar/cal-util/timeutil.c240
1 files changed, 13 insertions, 227 deletions
diff --git a/calendar/cal-util/timeutil.c b/calendar/cal-util/timeutil.c
index 933230872b..6bc893831d 100644
--- a/calendar/cal-util/timeutil.c
+++ b/calendar/cal-util/timeutil.c
@@ -17,20 +17,11 @@ print_time_t (time_t t)
{
struct tm *tm = localtime (&t);
- printf ("TIEMPO: %d/%d/%d %d:%d:%d\n",
- tm->tm_mon+1, tm->tm_mday, tm->tm_year,
+ printf ("%d/%02d/%02d %02d:%02d:%02d",
+ 1900 + tm->tm_year, tm->tm_mon+1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
}
-int
-get_time_t_hour (time_t t)
-{
- struct tm *tm;
-
- tm = localtime (&t);
- return tm->tm_hour;
-}
-
char *
isodate_from_time_t (time_t t)
{
@@ -43,43 +34,17 @@ isodate_from_time_t (time_t t)
}
time_t
-time_from_start_duration (time_t start, char *duration)
-{
- printf ("Not yet implemented\n");
- return 0;
-}
-
-char *
-format_simple_hour (int hour, int use_am_pm)
-{
- static char buf[256];
-
- /* I don't know whether this is the best way to internationalize it.
- * Does any language use different conventions? - Federico
- */
-
- if (use_am_pm)
- g_snprintf (buf, sizeof(buf), "%d%s",
- (hour == 0) ? 12 : (hour > 12) ? (hour - 12) : hour,
- (hour < 12) ? _("am") : _("pm"));
- else
- g_snprintf (buf, sizeof(buf), "%02d%s", hour, _("h"));
-
- return buf;
-
-}
-
-time_t
time_add_minutes (time_t time, int minutes)
{
struct tm *tm = localtime (&time);
time_t new_time;
tm->tm_min += minutes;
- if ((new_time = mktime (tm)) == -1){
+ if ((new_time = mktime (tm)) == -1) {
g_message ("time_add_minutes(): mktime() could not handle "
"adding %d minutes with\n", minutes);
print_time_t (time);
+ printf ("\n");
return time;
}
return new_time;
@@ -104,20 +69,21 @@ time_add_day (time_t time, int days)
tm->tm_mday += days;
tm->tm_isdst = -1;
- if ((new_time = mktime (tm)) == -1){
+ if ((new_time = mktime (tm)) == -1) {
g_message ("time_add_day(): mktime() could not handling adding %d days with\n",
days);
print_time_t (time);
+ printf ("\n");
return time;
}
#if 0
/* I don't know what this is for. See also time_day_begin() and
time_day_end(). - Damon. */
- if (dst_flag > tm->tm_isdst){
+ if (dst_flag > tm->tm_isdst) {
tm->tm_hour++;
new_time += 3600;
- } else if (dst_flag < tm->tm_isdst){
+ } else if (dst_flag < tm->tm_isdst) {
tm->tm_hour--;
new_time -= 3600;
}
@@ -143,14 +109,15 @@ time_add_month (time_t time, int months)
tm->tm_mon += months;
tm->tm_isdst = -1;
- if ((new_time = mktime (tm)) == -1){
+ if ((new_time = mktime (tm)) == -1) {
g_message ("time_add_month(): mktime() could not handling adding %d months with\n",
months);
print_time_t (time);
+ printf ("\n");
return time;
}
tm = localtime (&new_time);
- if (tm->tm_mday < mday){
+ if (tm->tm_mday < mday) {
tm->tm_mon--;
tm->tm_mday = time_days_in_month (tm->tm_year+1900, tm->tm_mon);
return new_time = mktime (tm);
@@ -166,28 +133,16 @@ time_add_year (time_t time, int years)
time_t new_time;
tm->tm_year += years;
- if ((new_time = mktime (tm)) == -1){
+ if ((new_time = mktime (tm)) == -1) {
g_message ("time_add_year(): mktime() could not handling adding %d years with\n",
years);
print_time_t (time);
+ printf ("\n");
return time;
}
return new_time;
}
-time_t
-time_day_hour (time_t t, int hour)
-{
- struct tm tm;
-
- tm = *localtime (&t);
- tm.tm_hour = hour;
- tm.tm_min = 0;
- tm.tm_sec = 0;
-
- return mktime (&tm);
-}
-
/* Number of days in a month, for normal and leap years */
static const int days_in_month[2][12] = {
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
@@ -329,7 +284,6 @@ time_week_end (time_t t)
time_t
time_day_begin (time_t t)
{
-#if 1
struct tm tm;
tm = *localtime (&t);
@@ -339,44 +293,12 @@ time_day_begin (time_t t)
tm.tm_isdst = -1;
return mktime (&tm);
-
-#else
- /* This is the original code which sometimes produces a time of 1:00.
- I don't understand why it looked at the tm_isdst flags at all.
- - Damon. */
-
- struct tm tm;
- time_t temp = t - 43200;
- int dstflag, dstflag2;
-
- tm = *localtime(&temp); /* one day */
- dstflag = tm.tm_isdst;
-
- tm = *localtime (&t);
- dstflag2 = tm.tm_isdst;
-
- if (dstflag < dstflag2)
- tm.tm_hour = 1;
- else
- tm.tm_hour = 0;
-
- tm.tm_min = 0;
- tm.tm_sec = 0;
-
- temp = mktime(&tm);
- if (dstflag > dstflag2){
- temp += 3600;
- }
-
- return temp;
-#endif
}
/* Returns the end of the day, according to the local time. */
time_t
time_day_end (time_t t)
{
-#if 1
struct tm tm;
tm = *localtime (&t);
@@ -387,140 +309,4 @@ time_day_end (time_t t)
tm.tm_isdst = -1;
return mktime (&tm);
-
-#else
- /* This is the original code which has more problems than
- time_day_begin(). - Damon. */
-
- struct tm tm;
- time_t temp;
- int dstflag, dstflag2;
-
- t += 10800;
- temp = t - 86400;
-
- tm = *localtime(&temp); /* one day */
- dstflag = tm.tm_isdst;
-
- tm = *localtime (&t);
- dstflag2 = tm.tm_isdst;
-
- if (dstflag < dstflag2)
- tm.tm_hour = 23;
- else {
- tm.tm_mday++;
- tm.tm_hour = 0;
- }
- tm.tm_min = 0;
- tm.tm_sec = 0;
-
- temp = mktime(&tm);
- if(dstflag > dstflag2) {
- }
- return temp;
-#endif
-}
-
-static char *
-pcat (char *dest, int num, char key)
-{
- int c;
-
- c = sprintf (dest, "%d%c", num, key);
- return dest + c;
-}
-
-/* Converts secs into the ISO difftime representation */
-char *
-isodiff_from_secs (int secs)
-{
- static char buffer [60], *p;
- int years, months, weeks, days, hours, minutes;
-
- years = months = weeks = days = hours = minutes = 0;
-
- years = secs / (365 * 86400);
- secs %= (365 * 86400);
- months = secs / (30 * 86400);
- secs %= (30 * 86400);
- weeks = secs / (7 * 86400);
- secs %= (7 * 86400);
- days = secs / 86400;
- secs %= 86400;
- hours = secs / 3600;
- secs %= 3600;
- minutes = secs / 60;
- secs %= 60;
-
- strcpy (buffer, "P");
- p = buffer + 1;
- if (years)
- p = pcat (p, years, 'Y');
- if (months)
- p = pcat (p, months, 'M');
- if (weeks)
- p = pcat (p, weeks, 'W');
- if (days)
- p = pcat (p, days, 'D');
- if (hours || minutes || secs){
- *p++ = 'T';
- if (hours)
- p = pcat (p, hours, 'H');
- if (minutes)
- p = pcat (p, minutes, 'M');
- if (secs)
- p = pcat (p, secs, 'S');
- }
-
- return buffer;
-}
-
-int
-isodiff_to_secs (char *str)
-{
- int value, time;
- int years, months, weeks, days, hours, minutes, seconds;
-
- value = years = months = weeks = days = hours = minutes = time = seconds = 0;
- if (*str != 'P')
- return 0;
-
- str++;
- while (*str){
- switch (*str){
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- value = value * 10 + (*str - '0');
- break;
- case 'Y':
- years = value; value = 0;
- break;
- case 'M':
- if (time)
- minutes = value;
- else
- months = value;
- value = 0;
- break;
- case 'W':
- weeks = value; value = 0;
- break;
- case 'D':
- days = value; value = 0;
- break;
- case 'T':
- value = 0; time = 1;
- break;
- case 'H':
- hours = value; value = 0;
- break;
- case 'S':
- seconds = value; value = 0;
- break;
- }
- str++;
- }
- return seconds + (minutes * 60) + (hours * 3600) +
- (days * 86400) + (weeks * 7 * 86400) +
- (months * 30 * 86400) + (years * 365 * 86400);
}