[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[pdf-devel] libgnupdf ChangeLog src/base/pdf-time.c
From: |
Aleksander Morgado |
Subject: |
[pdf-devel] libgnupdf ChangeLog src/base/pdf-time.c |
Date: |
Fri, 04 Jul 2008 17:26:48 +0000 |
CVSROOT: /cvsroot/pdf
Module name: libgnupdf
Changes by: Aleksander Morgado <aleksander_m> 08/07/04 17:26:48
Modified files:
. : ChangeLog
src/base : pdf-time.c
Log message:
Take into account that structure members in pdf_time_cal_span_s are
unsigned
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libgnupdf/ChangeLog?cvsroot=pdf&r1=1.272&r2=1.273
http://cvs.savannah.gnu.org/viewcvs/libgnupdf/src/base/pdf-time.c?cvsroot=pdf&r1=1.5&r2=1.6
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/pdf/libgnupdf/ChangeLog,v
retrieving revision 1.272
retrieving revision 1.273
diff -u -b -r1.272 -r1.273
--- ChangeLog 4 Jul 2008 16:38:08 -0000 1.272
+++ ChangeLog 4 Jul 2008 17:26:47 -0000 1.273
@@ -1,5 +1,10 @@
2008-07-04 Aleksander Morgado Juez <address@hidden>
+ * src/base/pdf-time.c (pdf_time_diff_cal): Take into account that
+ structure members inside `pdf_time_cal_span_s' are all unsigned.
+
+2008-07-04 Aleksander Morgado Juez <address@hidden>
+
* src/base/pdf-time.c (pdf_time_cal_span_diff): Function implemented
and some other bugfixes related to calendar spans, which are not
funny any more.
Index: src/base/pdf-time.c
===================================================================
RCS file: /cvsroot/pdf/libgnupdf/src/base/pdf-time.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- src/base/pdf-time.c 4 Jul 2008 16:38:08 -0000 1.5
+++ src/base/pdf-time.c 4 Jul 2008 17:26:48 -0000 1.6
@@ -754,26 +754,51 @@
PDF_TIME_CAL_UTC,
&calendar2) == PDF_OK) )
{
- /* Now, directly get calendar diff */
- p_cal_span->years = calendar2.year - calendar1.year;
- p_cal_span->months = calendar2.month - calendar1.month;
- p_cal_span->days = calendar2.day - calendar1.day;
- p_cal_span->hours = calendar2.hour - calendar1.hour;
- p_cal_span->minutes = calendar2.minute - calendar1.minute;
- p_cal_span->seconds = calendar2.second - calendar1.second;
- p_cal_span->sign = PDF_FALSE;
+ struct pdf_time_cal_s *p_big;
+ struct pdf_time_cal_s *p_small;
+ pdf_i32_t aux;
- /* Maybe time1 was greater than time2... */
+ /* Check which of the dates is bigger */
if(pdf_time_cmp(time1, time2) > 0)
{
- p_cal_span->years *= (-1);
- p_cal_span->months *= (-1);
- p_cal_span->days *= (-1);
- p_cal_span->hours *= (-1);
- p_cal_span->minutes *= (-1);
- p_cal_span->seconds *= (-1);
p_cal_span->sign = PDF_TRUE;
+ p_big = &calendar1;
+ p_small = &calendar2;
+ }
+ else
+ {
+ p_cal_span->sign = PDF_FALSE;
+ p_big = &calendar2;
+ p_small = &calendar1;
}
+
+ /* Get diff of years directly (always + or 0) */
+ p_cal_span->years = p_big->year - p_small->year;
+
+#define DIFF_AND_CORRECT(field,spanfield,spanupperfield) \
+ do { \
+ aux = p_big->field - p_small->field; \
+ if(aux < 0) { \
+ p_cal_span->spanupperfield--; \
+ p_cal_span->spanfield = (-1)*aux; \
+ } else { \
+ p_cal_span->spanfield = aux; \
+ } \
+ } while(0)
+
+ /* Get diff of months (could be -) */
+ DIFF_AND_CORRECT(month, months, years);
+ /* Get diff of days (could be -) */
+ DIFF_AND_CORRECT(day, days, months);
+ /* Get diff of hours (could be -) */
+ DIFF_AND_CORRECT(hour, hours, days);
+ /* Get diff of minutes (could be -) */
+ DIFF_AND_CORRECT(minute, minutes, hours);
+ /* Get diff of seconds (could be -) */
+ DIFF_AND_CORRECT(second, seconds, minutes);
+
+#undef DIFF_AND_CORRECT
+
ret_code = PDF_OK;
}