[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: |
Tue, 01 Jul 2008 22:41:21 +0000 |
CVSROOT: /cvsroot/pdf
Module name: libgnupdf
Changes by: Aleksander Morgado <aleksander_m> 08/07/01 22:41:21
Modified files:
. : ChangeLog
doc : gnupdf.texi
src/base : pdf-time-string.c pdf-time.c pdf-time.h
Log message:
Added function to create ISO-8601 date & time strings
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libgnupdf/ChangeLog?cvsroot=pdf&r1=1.269&r2=1.270
http://cvs.savannah.gnu.org/viewcvs/libgnupdf/doc/gnupdf.texi?cvsroot=pdf&r1=1.76&r2=1.77
http://cvs.savannah.gnu.org/viewcvs/libgnupdf/src/base/pdf-time-string.c?cvsroot=pdf&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/libgnupdf/src/base/pdf-time.c?cvsroot=pdf&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/libgnupdf/src/base/pdf-time.h?cvsroot=pdf&r1=1.3&r2=1.4
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/pdf/libgnupdf/ChangeLog,v
retrieving revision 1.269
retrieving revision 1.270
diff -u -b -r1.269 -r1.270
--- ChangeLog 1 Jul 2008 22:11:56 -0000 1.269
+++ ChangeLog 1 Jul 2008 22:41:19 -0000 1.270
@@ -1,5 +1,19 @@
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.
+
+ * src/base/pdf-time.c (pdf_time_from_cal): Bugfix (one day less)
+ and gmt offset included.
+
+ * src/base/pdf-time.h: Remove not needed typedef.
+
+ * doc/gnupdf.texi (Time Printing and Parsing): Clarification.
+ The string returned by `pdf_time_to_string' must be deallocated
+ by the caller.
+
+2008-07-02 Aleksander Morgado Juez <address@hidden>
+
* src/base/pdf-time.h (struct pdf_time_s): Clarification. GMT
offset must be stored in seconds west of GMT.
Index: doc/gnupdf.texi
===================================================================
RCS file: /cvsroot/pdf/libgnupdf/doc/gnupdf.texi,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -b -r1.76 -r1.77
--- doc/gnupdf.texi 1 Jul 2008 22:11:56 -0000 1.76
+++ doc/gnupdf.texi 1 Jul 2008 22:41:20 -0000 1.77
@@ -1,5 +1,5 @@
\input texinfo
address@hidden $Id: gnupdf.texi,v 1.76 2008/07/01 22:11:56 aleksander_m Exp $
address@hidden $Id: gnupdf.texi,v 1.77 2008/07/01 22:41:20 aleksander_m Exp $
@comment %**start of header
@setfilename gnupdf.info
@settitle GNU PDF Library Reference
@@ -5245,17 +5245,19 @@
@end table
@item Returns
-The string representation of @var{time}.
+The string representation of @var{time}. Must be deallocated by the caller of
the function explicitly with pdf_dealloc().
@code{NULL} if there is an error.
@item Usage example
@example
pdf_time_t mytime;
-char *mytime_str;
+pdf_char_t *mytime_str;
/* ...create and manipulate `mytime'... */
mytime_str = pdf_time_to_string (mytime, PDF_TIME_FORMAT_PDF);
+
+pdf_dealloc(mytime_str);
@end example
@end table
@end deftypefun
Index: src/base/pdf-time-string.c
===================================================================
RCS file: /cvsroot/pdf/libgnupdf/src/base/pdf-time-string.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- src/base/pdf-time-string.c 27 Jun 2008 21:23:50 -0000 1.2
+++ src/base/pdf-time-string.c 1 Jul 2008 22:41:20 -0000 1.3
@@ -31,7 +31,7 @@
#include <pdf-time-string.h>
-
+#define PDF_MAX_ISO8601_STR_LENGTH 30
@@ -75,7 +75,7 @@
* Complete date plus hours, minutes and seconds:
* YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
* Complete date plus hours, minutes, seconds and a decimal fraction of a
- * secondca
+ * second
* YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
*
* where:
@@ -209,7 +209,36 @@
pdf_char_t *
pdf_time_to_string_iso8601(const pdf_time_t time_var)
{
- return NULL;
+ pdf_char_t *str;
+ struct pdf_time_cal_s calendar;
+
+ str = (pdf_char_t *)pdf_alloc(PDF_MAX_ISO8601_STR_LENGTH*sizeof(pdf_char_t));
+ if(str != NULL)
+ {
+ /* YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00) */
+ if(pdf_time_get_local_cal(time_var, &calendar) == PDF_OK)
+ {
+ 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);
+ }
+ else
+ {
+ PDF_DEBUG_BASE("Could not get local calendar from pdf_time_t...");
+ pdf_dealloc(str);
+ str = NULL;
+ }
+ }
+
+ return str;
}
Index: src/base/pdf-time.c
===================================================================
RCS file: /cvsroot/pdf/libgnupdf/src/base/pdf-time.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- src/base/pdf-time.c 27 Jun 2008 21:23:51 -0000 1.2
+++ src/base/pdf-time.c 1 Jul 2008 22:41:20 -0000 1.3
@@ -120,6 +120,16 @@
static pdf_bool_t
pdf_time_is_valid_cal_p(const struct pdf_time_cal_s *p_cal_time)
{
+/*
+ PDF_DEBUG_BASE("Calendar: %d/%d/%d %d:%d:%d off:%d",
+ p_cal_time->year,
+ p_cal_time->month,
+ p_cal_time->day,
+ p_cal_time->hour,
+ p_cal_time->minute,
+ p_cal_time->second,
+ p_cal_time->gmt_offset);
+*/
return ( ( (p_cal_time == NULL) || \
(p_cal_time->year < PDF_MINIMUM_YEAR) || \
(p_cal_time->month < PDF_TIME_JANUARY) || \
@@ -678,8 +688,8 @@
pdf_i64_add_i32(&aux, aux, pdf_time_get_days_before_month(p_cal_time->year,
p_cal_time->month));
- /* Add days in current month */
- pdf_i64_add_i32(&aux, aux, p_cal_time->day);
+ /* Add days in current month until the current required day */
+ pdf_i64_add_i32(&aux, aux, p_cal_time->day -1);
/* Set date as seconds in the output variable */
pdf_i64_mult_i32(&(time_var->seconds), aux, PDF_SECS_PER_DAY);
@@ -697,6 +707,19 @@
(time_var->seconds), \
p_cal_time->second);
+ /* Set specific GMT offset if any */
+ if(p_cal_time->gmt_offset != 0)
+ {
+ /* Add it to the time value */
+ 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);
+ pdf_time_span_destroy(&delta);
+
+ /* Store the applied offset */
+ time_var->gmt_offset = p_cal_time->gmt_offset;
+ }
+
return PDF_OK;
}
Index: src/base/pdf-time.h
===================================================================
RCS file: /cvsroot/pdf/libgnupdf/src/base/pdf-time.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- src/base/pdf-time.h 1 Jul 2008 22:11:57 -0000 1.3
+++ src/base/pdf-time.h 1 Jul 2008 22:41:20 -0000 1.4
@@ -42,7 +42,6 @@
/* A GMT offset, seconds WEST of GMT */
pdf_i32_t gmt_offset;
};
-typedef int intaleks;
typedef struct pdf_time_s *pdf_time_t;