aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamon Chaplin <damon@helixcode.com>2000-05-07 06:46:54 +0800
committerDamon Chaplin <damon@src.gnome.org>2000-05-07 06:46:54 +0800
commitd1694fef3e63cb4e3e4bf5133222b02e940ff883 (patch)
treed86275a4692a73c6c68e66b6f69d3f16a552f2d3
parent35e0a09b15b04e454e5faef81670155282cee0a7 (diff)
downloadgsoc2013-evolution-d1694fef3e63cb4e3e4bf5133222b02e940ff883.tar
gsoc2013-evolution-d1694fef3e63cb4e3e4bf5133222b02e940ff883.tar.gz
gsoc2013-evolution-d1694fef3e63cb4e3e4bf5133222b02e940ff883.tar.bz2
gsoc2013-evolution-d1694fef3e63cb4e3e4bf5133222b02e940ff883.tar.lz
gsoc2013-evolution-d1694fef3e63cb4e3e4bf5133222b02e940ff883.tar.xz
gsoc2013-evolution-d1694fef3e63cb4e3e4bf5133222b02e940ff883.tar.zst
gsoc2013-evolution-d1694fef3e63cb4e3e4bf5133222b02e940ff883.zip
changed these so they just do a simple localtime(), update the struct tm,
2000-05-06 Damon Chaplin <damon@helixcode.com> * cal-util/timeutil.c (time_day_begin): (time_day_end): changed these so they just do a simple localtime(), update the struct tm, then do a mktime(). I don't know why it used to look at the tm_isdst flags etc. From a little test program I wrote which steps through testing every hour for a year it wasn't working correctly, and the new code does. (time_add_day): also got rid of the stuff that looked at tm_isdst here. My test program now works better. svn path=/trunk/; revision=2841
-rw-r--r--calendar/ChangeLog11
-rw-r--r--calendar/cal-util/timeutil.c49
2 files changed, 60 insertions, 0 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index 87bebd3723..b4f03b7cf7 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,14 @@
+2000-05-06 Damon Chaplin <damon@helixcode.com>
+
+ * cal-util/timeutil.c (time_day_begin):
+ (time_day_end): changed these so they just do a simple localtime(),
+ update the struct tm, then do a mktime(). I don't know why it used to
+ look at the tm_isdst flags etc. From a little test program I wrote
+ which steps through testing every hour for a year it wasn't working
+ correctly, and the new code does.
+ (time_add_day): also got rid of the stuff that looked at tm_isdst here.
+ My test program now works better.
+
2000-05-06 Chris Toshok <toshok@helixcode.com>
* gui/.cvsignore: ignore evolution-calendar.pure
diff --git a/calendar/cal-util/timeutil.c b/calendar/cal-util/timeutil.c
index 7ddc0e04d4..2f9156a6f5 100644
--- a/calendar/cal-util/timeutil.c
+++ b/calendar/cal-util/timeutil.c
@@ -116,12 +116,21 @@ time_add_minutes (time_t time, int minutes)
return new_time;
}
+/* Adds a day onto the time, using local time.
+ Note that if clocks go forward due to daylight savings time, there are
+ some non-existent local times, so the hour may be changed to make it a
+ valid time. This also means that it may not be wise to keep calling
+ time_add_day() to step through a certain period - if the hour gets changed
+ to make it valid time, any further calls to time_add_day() will also return
+ this hour, which may not be what you want. */
time_t
time_add_day (time_t time, int days)
{
struct tm *tm = localtime (&time);
time_t new_time;
+#if 0
int dst_flag = tm->tm_isdst;
+#endif
tm->tm_mday += days;
@@ -131,6 +140,9 @@ time_add_day (time_t time, int days)
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){
tm->tm_hour++;
new_time += 3600;
@@ -138,6 +150,7 @@ time_add_day (time_t time, int days)
tm->tm_hour--;
new_time -= 3600;
}
+#endif
return new_time;
}
@@ -336,9 +349,26 @@ time_week_end (time_t t)
return mktime (&tm);
}
+/* Returns the start of the day, according to the local time. */
time_t
time_day_begin (time_t t)
{
+#if 1
+ struct tm tm;
+
+ tm = *localtime (&t);
+ tm.tm_hour = 0;
+ tm.tm_min = 0;
+ tm.tm_sec = 0;
+ 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;
@@ -363,11 +393,29 @@ time_day_begin (time_t t)
}
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);
+ tm.tm_mday++;
+ tm.tm_hour = 0;
+ tm.tm_min = 0;
+ tm.tm_sec = 0;
+ 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;
@@ -394,6 +442,7 @@ time_day_end (time_t t)
if(dstflag > dstflag2) {
}
return temp;
+#endif
}
static char *