[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[pdf-devel] libgnupdf ChangeLog doc/gnupdf.texi src/base/pd...
From: |
Aleksander Morgado |
Subject: |
[pdf-devel] libgnupdf ChangeLog doc/gnupdf.texi src/base/pd... |
Date: |
Wed, 02 Jul 2008 20:28:42 +0000 |
CVSROOT: /cvsroot/pdf
Module name: libgnupdf
Changes by: Aleksander Morgado <aleksander_m> 08/07/02 20:28:42
Modified files:
. : ChangeLog
doc : gnupdf.texi
src/base : pdf-time-string.c pdf-time.c
Log message:
Seconds stored within the pdf_time_t are always UTC. GMT offset is
stored separately, never applied to the epoch
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libgnupdf/ChangeLog?cvsroot=pdf&r1=1.270&r2=1.271
http://cvs.savannah.gnu.org/viewcvs/libgnupdf/doc/gnupdf.texi?cvsroot=pdf&r1=1.77&r2=1.78
http://cvs.savannah.gnu.org/viewcvs/libgnupdf/src/base/pdf-time-string.c?cvsroot=pdf&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/libgnupdf/src/base/pdf-time.c?cvsroot=pdf&r1=1.3&r2=1.4
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/pdf/libgnupdf/ChangeLog,v
retrieving revision 1.270
retrieving revision 1.271
diff -u -b -r1.270 -r1.271
--- ChangeLog 1 Jul 2008 22:41:19 -0000 1.270
+++ ChangeLog 2 Jul 2008 20:28:41 -0000 1.271
@@ -1,5 +1,17 @@
2008-07-02 Aleksander Morgado Juez <address@hidden>
+ * src/base/pdf-time.c: Basic bugfixes to always store the epoch
+ in UTC within the `pdf_time_t'. GMT offset is stored separately.
+
+ * src/base/pdf-time-string.c (pdf_time_from_string_iso8601): Get
+ `pdf_time_cal_s' from string in UTC, then convert it to a
+ `pdf_time_t'.
+
+ * doc/gnupdf.texi (Time Related Data Types): Clarification on the
+ use of `struct pdf_time_cal_s'.
+
+2008-07-02 Aleksander Morgado Juez <address@hidden>
+
* src/base/pdf-time-string.c (pdf_time_to_string_iso8601): Function
implemented. Remember to pdf_dealloc-ate the returned string.
Index: doc/gnupdf.texi
===================================================================
RCS file: /cvsroot/pdf/libgnupdf/doc/gnupdf.texi,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -b -r1.77 -r1.78
--- doc/gnupdf.texi 1 Jul 2008 22:41:20 -0000 1.77
+++ doc/gnupdf.texi 2 Jul 2008 20:28:41 -0000 1.78
@@ -1,5 +1,5 @@
\input texinfo
address@hidden $Id: gnupdf.texi,v 1.77 2008/07/01 22:41:20 aleksander_m Exp $
address@hidden $Id: gnupdf.texi,v 1.78 2008/07/02 20:28:41 aleksander_m Exp $
@comment %**start of header
@setfilename gnupdf.info
@settitle GNU PDF Library Reference
@@ -4573,6 +4573,10 @@
calendar items: years, months, days, day of week, hours, minutes,
seconds and the relative offset with GMT.
+The calendar can be represented in both UTC and local time. If the given GMT
+offset is zero, the calendar fields come in UTC; if not zero, the calendar
+fields come in a given local time.
+
@table @code
@item pdf_i32_t year
A year number. Negative values may be supported in some systems.
Index: src/base/pdf-time-string.c
===================================================================
RCS file: /cvsroot/pdf/libgnupdf/src/base/pdf-time-string.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- src/base/pdf-time-string.c 1 Jul 2008 22:41:20 -0000 1.3
+++ src/base/pdf-time-string.c 2 Jul 2008 20:28:41 -0000 1.4
@@ -93,6 +93,8 @@
struct pdf_time_cal_s calendar;
pdf_char_t *duplicate;
pdf_char_t *walker;
+ pdf_status_t ret_code;
+ pdf_i32_t gmt_offset;
pdf_size_t time_str_length = strlen((char *)time_str);
/* Check minimum length */
@@ -142,7 +144,7 @@
calendar.hour = atoi((char *)(&duplicate[11]));
/* Get minutes */
duplicate[16] = '\0';
- calendar.hour = atoi((char *)(&duplicate[14]));
+ calendar.minute = atoi((char *)(&duplicate[14]));
/* Get Time Zone information */
if(duplicate[time_str_length-1] == 'Z')
@@ -159,10 +161,10 @@
duplicate[time_str_length-3] = '\0';
hours_tz = atoi((char *)(&duplicate[time_str_length-5]));
- calendar.gmt_offset = 60*(minutes_tz + 60*hours_tz);
+ gmt_offset = 60*(minutes_tz + 60*hours_tz);
if(duplicate[time_str_length-6] == '-')
{
- calendar.gmt_offset *= (-1);
+ gmt_offset *= (-1);
}
}
@@ -178,8 +180,34 @@
}
}
- /* Get time value from break-down calendar */
- return pdf_time_from_cal(time_var, &calendar);
+ /* Set calendar as if it were UTC */
+ calendar.gmt_offset = 0;
+
+/*
+ pdf_char_t *str = (pdf_char_t
*)pdf_alloc(PDF_MAX_ISO8601_STR_LENGTH*sizeof(pdf_char_t));
+ pdf_i32_t offset_hours = calendar.gmt_offset / 3600;
+ pdf_i32_t offset_minutes = calendar.gmt_offset % 3600;
+ sprintf((char *)str, "%4d-%s%d-%s%dT%s%d:%s%d:%s%d.00+%s%d:%s%d", \
+ calendar.year,
+ (calendar.month < 10 ? "0" : ""), calendar.month,
+ (calendar.day < 10 ? "0" : ""), calendar.day,
+ (calendar.hour < 10 ? "0" : ""), calendar.hour,
+ (calendar.minute < 10 ? "0" : ""), calendar.minute,
+ (calendar.second < 10 ? "0" : ""), calendar.second,
+ (offset_hours < 10 ? "0" : ""), offset_hours,
+ (offset_minutes < 10 ? "0" : ""), offset_minutes);
+ PDF_DEBUG_BASE("Intermediate calendar: %s", str);
+*/
+
+ /* Get time value from break-down UTC calendar !*/
+ ret_code = pdf_time_from_cal(time_var, &calendar);
+ if(ret_code == PDF_OK)
+ {
+ /* Now set GMT offset in pdf_time_t */
+ time_var->gmt_offset = gmt_offset;
+ }
+
+ return ret_code;
}
Index: src/base/pdf-time.c
===================================================================
RCS file: /cvsroot/pdf/libgnupdf/src/base/pdf-time.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- src/base/pdf-time.c 1 Jul 2008 22:41:20 -0000 1.3
+++ src/base/pdf-time.c 2 Jul 2008 20:28:41 -0000 1.4
@@ -162,20 +162,20 @@
/* Duplicate time var */
new_time_var = pdf_time_dup(time_var);
- /* If requested local calendar, and we have utc time, remove gmt offset */
+ /* pdf_time_t always stores the date & time in UTC timescale, so we only need
+ * to modify the time_var IF gmt_offset is not zero, in order to move the
+ * date & time from UTC to local time specified by the offset */
if( (cal_type == PDF_TIME_CAL_LOCAL) && \
- (time_var->gmt_offset == 0) )
- {
- pdf_time_set_to_current_local_time(new_time_var);
- }
- /* If requested utc calendar, and we have local time, add gmt offset */
- else if( (cal_type == PDF_TIME_CAL_UTC) && \
(time_var->gmt_offset != 0) )
{
- pdf_time_set_to_current_utc_time(new_time_var);
+ pdf_time_span_t delta;
+ /* Modify time in the time object */
+ delta = pdf_time_span_new();
+ pdf_time_span_set_from_i32(&delta, time_var->gmt_offset);
+ pdf_time_add_span(time_var, delta);
+ pdf_time_span_destroy(&delta);
}
-
days = pdf_i64_new(0,0);
aux64 = pdf_i64_new(0,0);
remaining = pdf_i64_new(0,0);
@@ -710,15 +710,18 @@
/* Set specific GMT offset if any */
if(p_cal_time->gmt_offset != 0)
{
- /* Add it to the time value */
+ /* Remove it from the time value (calendar comes in local time, so
+ * we must remove the offset to get the pdf_time_t->seconds in UTC. */
pdf_time_span_t delta = pdf_time_span_new();
pdf_time_span_set_from_i32(&delta, p_cal_time->gmt_offset);
- pdf_time_add_span(time_var, delta);
+ printf("Before sub: %d\n", pdf_i64_to_i32(time_var->seconds));
+ pdf_time_sub_span(time_var, delta);
+ printf("After sub: %d\n", pdf_i64_to_i32(time_var->seconds));
pdf_time_span_destroy(&delta);
+ }
- /* Store the applied offset */
+ /* Store the offset */
time_var->gmt_offset = p_cal_time->gmt_offset;
- }
return PDF_OK;
}
@@ -727,26 +730,8 @@
pdf_status_t
pdf_time_set_local_offset (pdf_time_t time_var)
{
- /* Set local offset and correct the actual time */
- if(time_var->gmt_offset != 0)
- {
- PDF_DEBUG_BASE("Time object already in local timescale");
- return PDF_EBADDATA;
- }
- else
- {
- pdf_time_span_t delta;
-
- /* Set GMT offset */
+ /* Set local GMT offset */
time_var->gmt_offset = pdf_time_context_get_gmt_offset();
-
- /* Modify time in the time object */
- delta = pdf_time_span_new();
- pdf_time_span_set_from_i32(&delta, time_var->gmt_offset);
- pdf_time_add_span(time_var, delta);
- pdf_time_span_destroy(&delta);
- }
-
return PDF_OK;
}
@@ -860,12 +845,7 @@
{
if(pdf_time_set_to_current_utc_time(time_var) == PDF_OK)
{
- /* And correct time with GMT offset */
- pdf_i64_subtraction_i32_sub(&(time_var->seconds),
- time_var->seconds,
- pdf_time_context_get_gmt_offset());
-
- /* And store applied offset in the gmt_offset */
+ /* And store offset in the gmt_offset */
time_var->gmt_offset = pdf_time_context_get_gmt_offset();
return PDF_OK;
}