[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: |
Fri, 27 Jun 2008 21:23:51 +0000 |
CVSROOT: /cvsroot/pdf
Module name: libgnupdf
Changes by: Aleksander Morgado <aleksander_m> 08/06/27 21:23:51
Modified files:
. : ChangeLog
doc : gnupdf.texi
src/base : pdf-time-context.c pdf-time-string.c pdf-time.c
pdf-time.h
Log message:
Changed the API of the time module so that structures are passed by the
means of their address, not a full copy of the structure
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libgnupdf/ChangeLog?cvsroot=pdf&r1=1.267&r2=1.268
http://cvs.savannah.gnu.org/viewcvs/libgnupdf/doc/gnupdf.texi?cvsroot=pdf&r1=1.74&r2=1.75
http://cvs.savannah.gnu.org/viewcvs/libgnupdf/src/base/pdf-time-context.c?cvsroot=pdf&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/libgnupdf/src/base/pdf-time-string.c?cvsroot=pdf&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/libgnupdf/src/base/pdf-time.c?cvsroot=pdf&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/libgnupdf/src/base/pdf-time.h?cvsroot=pdf&r1=1.1&r2=1.2
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/pdf/libgnupdf/ChangeLog,v
retrieving revision 1.267
retrieving revision 1.268
diff -u -b -r1.267 -r1.268
--- ChangeLog 25 Jun 2008 19:46:57 -0000 1.267
+++ ChangeLog 27 Jun 2008 21:23:49 -0000 1.268
@@ -1,3 +1,16 @@
+2008-06-27 Aleksander Morgado Juez <address@hidden>
+
+ * src/base/pdf-time.[c|h]: When passing a struct to a function, do
+ it by the means of its address, not a copy of the whole structure.
+
+ * doc/gnupdf.texi (Time Module API): Idem.
+
+ * src/base/pdf-time-string.c (pdf_time_from_string_iso8601): Changed
+ to use new time module API.
+
+ * src/base/pdf-time-context.c (pdf_time_context_init): Store gmt
+ offset in seconds, not in minutes.
+
2008-06-25 Jose E. Marchesi <address@hidden>
* prmgt/generate-coverage-report: New script to generate an html
Index: doc/gnupdf.texi
===================================================================
RCS file: /cvsroot/pdf/libgnupdf/doc/gnupdf.texi,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -b -r1.74 -r1.75
--- doc/gnupdf.texi 15 Jun 2008 18:04:47 -0000 1.74
+++ doc/gnupdf.texi 27 Jun 2008 21:23:50 -0000 1.75
@@ -1,5 +1,5 @@
\input texinfo
address@hidden $Id: gnupdf.texi,v 1.74 2008/06/15 18:04:47 aleksander_m Exp $
address@hidden $Id: gnupdf.texi,v 1.75 2008/06/27 21:23:50 aleksander_m Exp $
@comment %**start of header
@setfilename gnupdf.info
@settitle GNU PDF Library Reference
@@ -4775,8 +4775,8 @@
@end table
@end deftypefun
address@hidden pdf_status_t pdf_time_add_cal_span (pdf_time_t @var{time_var},
const struct pdf_time_cal_span_s @var{cal_span})
-Add the time span represented by @var{cal_span} to @var{time_var}.
address@hidden pdf_status_t pdf_time_add_cal_span (pdf_time_t @var{time_var},
const struct pdf_time_cal_span_s address@hidden)
+Add the time span represented by the calendar span under the address in
@var{p_cal_span} to @var{time_var}.
@table @strong
@item Parameters
@@ -4784,8 +4784,8 @@
@table @var
@item time_var
A properly created time variable.
address@hidden cal_span
-A calendar span with valid values.
address@hidden p_cal_span
+A pointer to a calendar span with valid values.
@end table
@item Returns
@@ -4794,7 +4794,7 @@
@item PDF_OK
The operation successfully finished.
@item PDF_EBADDATA
-The data in @var{cal_span} is invalid.
+The data in @var{*p_cal_span} is invalid.
@end table
@item Usage example
@@ -4811,7 +4811,7 @@
cal_span.minute = 0;
cal_span.second = 0;
-if (pdf_time_add_cal_span (mytime, cal_span) == PDF_EBADDATA)
+if (pdf_time_add_cal_span (mytime, &cal_span) == PDF_EBADDATA)
@{
/* Bad data in `cal_span' */
@}
@@ -4823,8 +4823,8 @@
@end table
@end deftypefun
address@hidden pdf_status_t pdf_time_sub_cal_span (pdf_time_t @var{time_var},
const struct pdf_time_cal_span_s @var{cal_span})
-Subtract the time span represented by @var{cal_span} to @var{time_var}.
address@hidden pdf_status_t pdf_time_sub_cal_span (pdf_time_t @var{time_var},
const struct pdf_time_cal_span_s address@hidden)
+Subtract the time span represented by the calendar span under the address in
@var{p_cal_span} to @var{time_var}.
@table @strong
@item Parameters
@@ -4832,8 +4832,8 @@
@table @var
@item time_var
A properly created time variable.
address@hidden cal_span
-A calendar span with valid values.
address@hidden p_cal_span
+A pointer to a calendar span with valid values.
@end table
@item Returns
@@ -4859,7 +4859,7 @@
cal_span.minute = 0;
cal_span.second = 0;
-if (pdf_time_add_cal_span (mytime, cal_span) == PDF_EBADDATA)
+if (pdf_time_add_cal_span (mytime, &cal_span) == PDF_EBADDATA)
@{
/* Bad data in `cal_span' */
@}
@@ -5014,7 +5014,7 @@
@end table
@end deftypefun
address@hidden pdf_status_t pdf_time_from_cal (pdf_time_t @var{time_var}, const
struct pdf_time_cal_s @var{cal_time})
address@hidden pdf_status_t pdf_time_from_cal (pdf_time_t @var{time_var}, const
struct pdf_time_cal_s address@hidden)
Set the value of a time variable to a given calendar time.
@table @strong
@@ -5023,8 +5023,8 @@
@table @var
@item time_var
A properl created time variable.
address@hidden cal_time
-A calendar time structure.
address@hidden p_cal_time
+A pointer to a calendar time structure.
@end table
@item Returns
@@ -5052,7 +5052,7 @@
mycaltime.sec = 0;
mycaltime.gmt_offset = 1;
-if (pdf_time_from_cal (mytime, mycaltime) == PDF_EBADDATA)
+if (pdf_time_from_cal (mytime, &mycaltime) == PDF_EBADDATA)
@{
/* Bad data in `mycaltime' */
@}
@@ -5130,7 +5130,7 @@
@end table
@end deftypefun
address@hidden pdf_status_t pdf_time_diff (const pdf_time_t @var{time1}, const
pdf_time_t @var{time2}, pdf_time_span_t @var{time_span})
address@hidden pdf_status_t pdf_time_diff (const pdf_time_t @var{time1}, const
pdf_time_t @var{time2}, pdf_time_span_t address@hidden)
Calculate the time span between two dates.
@table @strong
@@ -5141,10 +5141,10 @@
The beginning time. Should be a properly created time.
@item time2
The ending time. Should be a properly created time.
address@hidden time_span
-The time span variable that will hold the difference between
address@hidden p_time_span
+The pointer to the time span variable that will hold the difference between
@var{time1} and @var{time2}. Should be a properly created time
-span. Any previous content of @var{time_span} will be destroyed.
+span. Any previous content of @var{*p_time_span} will be destroyed.
@end table
@item Returns
@@ -5162,7 +5162,7 @@
/* ...create and manipulate `time1', `time2' and `time_span'... */
-pdf_time_diff (time1, time2, time_span);
+pdf_time_diff (time1, time2, &time_span);
@end example
@end table
@end deftypefun
@@ -5417,7 +5417,7 @@
@end deftypefun
address@hidden pdf_status_t pdf_time_span_destroy (pdf_time_span_t @var{span})
address@hidden pdf_status_t pdf_time_span_destroy (pdf_time_span_t
address@hidden)
Destroy a time span variable freeing all used memory.
@@ -5425,8 +5425,8 @@
@item Parameters
@table @var
address@hidden span
-The time span variable to be destroyed.
address@hidden p_span
+The pointer to the time span variable to be destroyed.
@end table
@item Returns
@@ -5449,7 +5449,7 @@
@node Managing Time Span Values
@subsection Managing Time Span Values
address@hidden pdf_status_t pdf_time_span_set (pdf_time_span_t @var{span},
const pdf_i32_t @var{high_value}, const pdf_u32_t @var{low_value})
address@hidden pdf_status_t pdf_time_span_set (pdf_time_span_t address@hidden,
const pdf_i32_t @var{high_value}, const pdf_u32_t @var{low_value})
Set the value of a time span. The internal representation of the time
span is 64 bits long (signed).
@@ -5458,8 +5458,8 @@
@item Parameters
@table @var
address@hidden span
-A properly created time span variable.
address@hidden p_span
+A pointer to a properly created time span variable.
@item high_value
The high (signed) part of the time span value.
@item low_value
@@ -5478,12 +5478,12 @@
pdf_time_span_t span;
span = pdf_time_span_new ();
-pdf_time_span_set (span, (32 << 1), 10); /* The span is -10 seconds long */
+pdf_time_span_set (&span, (32 << 1), 10); /* The span is -10 seconds long */
@end example
@end table
@end deftypefun
address@hidden pdf_status_t pdf_time_span_set_from_i32 (pdf_time_span_t
@var{span}, const pdf_i32_t @var{seconds})
address@hidden pdf_status_t pdf_time_span_set_from_i32 (pdf_time_span_t
address@hidden, const pdf_i32_t @var{seconds})
Set the value of a time span from a 32 bits signed number.
@@ -5491,8 +5491,8 @@
@item Parameters
@table @var
address@hidden span
-A properly created time span variable.
address@hidden p_span
+A pointer to a properly created time span variable.
@item seconds
A signed 32 bits number.
@end table
@@ -5509,7 +5509,7 @@
pdf_time_span_t span;
span = pdf_time_span_create ();
-pdf_time_span_set_from_i32 (span, -10); /* The span is -10 seconds long */
+pdf_time_span_set_from_i32 (&span, -10); /* The span is -10 seconds long */
@end example
@end table
@end deftypefun
@@ -5545,7 +5545,7 @@
@end table
@end deftypefun
address@hidden pdf_status_t pdf_time_span_add (const pdf_time_span_t
@var{span1}, const pdf_time_span_t @var{span2}, pdf_time_span_t @var{result})
address@hidden pdf_status_t pdf_time_span_add (const pdf_time_span_t
@var{span1}, const pdf_time_span_t @var{span2}, pdf_time_span_t address@hidden)
Add two time spans and store the result in another time span.
@@ -5557,8 +5557,8 @@
The first time span to add.
@item span2
The second time span to add.
address@hidden result
-The time span holding the result of the add operation. Any previous
address@hidden p_result
+The pointer to the time span holding the result of the add operation. Any
previous
content is lost.
@end table
@@ -5576,12 +5576,12 @@
pdf_time_span_t result;
/* ...create and manipulate `span1', `span2' and `result'... */
-pdf_time_span_add (span1, span2, result);
+pdf_time_span_add (span1, span2, &result);
@end example
@end table
@end deftypefun
address@hidden pdf_status_t pdf_time_span_copy (const pdf_time_span_t
@var{orig}, pdf_time_span_t @var{dest})
address@hidden pdf_status_t pdf_time_span_copy (const pdf_time_span_t
@var{orig}, pdf_time_span_t address@hidden)
Copy the value of a time span into another time span.
@@ -5591,8 +5591,8 @@
@table @var
@item orig
The origin time span.
address@hidden dest
-The time span variable that will hold the value of @var{orig}. Any
address@hidden p_dest
+The pointer to the time span variable that will hold the value of @var{orig}.
Any
previous value is lost.
@end table
@@ -5615,7 +5615,7 @@
@end table
@end deftypefun
address@hidden pdf_status_t pdf_time_span_diff (const pdf_time_span_t
@var{span1}, const pdf_time_span_t @var{span2}, pdf_time_span_t @var{result})
address@hidden pdf_status_t pdf_time_span_diff (const pdf_time_span_t
@var{span1}, const pdf_time_span_t @var{span2}, pdf_time_span_t address@hidden)
Difference two time spans and store the result (maybe negative) into
another time span.
@@ -5628,7 +5628,7 @@
The first time span to diff.
@item span2
The second time span to diff.
address@hidden result
address@hidden p_result
The result of the diff operation. Any previous value of the time span
is lost.
@end table
@@ -5739,7 +5739,7 @@
@node Calendar Spans Management
@subsection Calendar Spans Management
address@hidden pdf_status_t pdf_time_add_cal_span_with_base (const struct
pdf_time_cal_span_s @var{span1}, const struct pdf_time_cal_span_s @var{span2},
const pdf_time_t @var{base_time}, struct pdf_time_cal_span_s address@hidden)
address@hidden pdf_status_t pdf_time_add_cal_span_with_base (const struct
pdf_time_cal_span_s address@hidden, const struct pdf_time_cal_span_s
address@hidden, const pdf_time_t @var{base_time}, struct pdf_time_cal_span_s
address@hidden)
Add two calendar spans. Since the calendar spans are relative (some
years has more days than another) the calendar spans are first
@@ -5749,10 +5749,10 @@
@item Parameters
@table @var
address@hidden span1
-The first calendar span to add.
address@hidden span2
-The second calendar span to add.
address@hidden p_span1
+The pointer to the first calendar span to add.
address@hidden p_span2
+The pointer to the second calendar span to add.
@item base_time
The base time to use.
@item p_result
@@ -5779,8 +5779,8 @@
* and `cal_span2'...
*/
-if (pdf_time_add_cal_span_with_base (cal_span1,
- cal_span2,
+if (pdf_time_add_cal_span_with_base (&cal_span1,
+ &cal_span2,
mytime,
&cal_result) == PDF_EBADDATA)
@{
@@ -5791,7 +5791,7 @@
@end deftypefun
address@hidden pdf_i32_t pdf_time_cal_span_cmp (const struct
pdf_time_cal_span_s @var{span1}, const struct pdf_time_cal_span_s @var{span2},
const pdf_time_t @var{base_time})
address@hidden pdf_i32_t pdf_time_cal_span_cmp (const struct
pdf_time_cal_span_s address@hidden, const struct pdf_time_cal_span_s
address@hidden, const pdf_time_t @var{base_time}, pdf_status_t *p_ret_code)
Compare two calendar spans previously resolved with a given base time.
@@ -5799,26 +5799,28 @@
@item Parameters
@table @var
address@hidden span1
-The first calendar span to be compared.
address@hidden span2
-The second calendar span to be compared.
address@hidden p_span1
+The pointer to the first calendar span to be compared.
address@hidden p_span2
+The pointer to the second calendar span to be compared.
@item base_time
The used base time. Should be a correctly created time variable.
address@hidden p_ret_code
+Pointer to a status variable to store any error happened in the function.
@end table
@item Returns
@table @code
@item -1
-Given the base time, the time interval defined by @var{span1} is
-greater in length than the time interval defined by @var{span2}.
+Given the base time, the time interval defined by @var{p_span2} is
+greater in length than the time interval defined by @var{p_span1}.
@item 0
-Given the base time, the time inveral defined by @var{span1} is equal
-in length than the time interval defined by @var{span2}.
+Given the base time, the time inveral defined by @var{p_span1} is equal
+in length than the time interval defined by @var{p_span2}.
@item +1
-Given the base time, the time interval defined by @var{span2} is
-greater in length than the time interval defined by @var{span1}.
+Given the base time, the time interval defined by @var{p_span1} is
+greater in length than the time interval defined by @var{p_span2}.
@end table
@item Usage example
@@ -5829,7 +5831,7 @@
/* ...create and manipulate `mytime', `span1' and `span2'... */
-switch (pdf_time_cal_span_cmp (span1, span2, mytime))
+switch (pdf_time_cal_span_cmp (&span1, &span2, mytime))
@{
case -1:
@{
@@ -5851,7 +5853,7 @@
@end table
@end deftypefun
address@hidden pdf_status_t pdf_time_cal_span_diff (const struct
pdf_time_cal_span_s @var{span1}, const struct pdf_time_cal_span_s @var{span2},
const pdf_time_t @var{base_time}, struct pdf_time_cal_span_s address@hidden)
address@hidden pdf_status_t pdf_time_cal_span_diff (const struct
pdf_time_cal_span_s address@hidden, const struct pdf_time_cal_span_s
address@hidden, const pdf_time_t @var{base_time}, struct pdf_time_cal_span_s
address@hidden)
Compute the difference between two calendar spans relative to a given
base time and store it in a given calendar span.
@@ -5860,10 +5862,10 @@
@item Parameters
@table @var
address@hidden span1
-The first calendar span to diff.
address@hidden span2
-The second calendar span to diff.
address@hidden p_span1
+The pointer to the first calendar span to diff.
address@hidden p_span2
+The pointer to the second calendar span to diff.
@item base_time
The base time. Should be a correctly created time variable.
@item p_result
@@ -5890,8 +5892,8 @@
* `result'...
*/
-if (pdf_time_cal_span_diff (span1,
- span2,
+if (pdf_time_cal_span_diff (&span1,
+ &span2,
mytime,
&result) == PDF_EBADDATA)
@{
Index: src/base/pdf-time-context.c
===================================================================
RCS file: /cvsroot/pdf/libgnupdf/src/base/pdf-time-context.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- src/base/pdf-time-context.c 24 Jun 2008 23:22:57 -0000 1.1
+++ src/base/pdf-time-context.c 27 Jun 2008 21:23:50 -0000 1.2
@@ -52,13 +52,14 @@
tzset();
/* Set GMT offset */
- time_context.local_time_gmt_offset = 60*timezone;
+ time_context.local_time_gmt_offset = timezone;
+
/* Set flag to indicate if Daylight saving times are applied in the system
* if needed */
time_context.local_time_daylight_save = (daylight == 0) ? PDF_FALSE :
PDF_TRUE;
PDF_DEBUG_BASE("Initializing Time module...");
- PDF_DEBUG_BASE("GMT offset: %d min", time_context.local_time_gmt_offset);
+ PDF_DEBUG_BASE("GMT offset: %d secs", time_context.local_time_gmt_offset);
PDF_DEBUG_BASE("Daylight saving? %s",time_context.local_time_daylight_save ?
\
"yes":"no");
Index: src/base/pdf-time-string.c
===================================================================
RCS file: /cvsroot/pdf/libgnupdf/src/base/pdf-time-string.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- src/base/pdf-time-string.c 24 Jun 2008 23:22:57 -0000 1.1
+++ src/base/pdf-time-string.c 27 Jun 2008 21:23:50 -0000 1.2
@@ -179,7 +179,7 @@
}
/* Get time value from break-down calendar */
- return pdf_time_from_cal(time_var, calendar);
+ return pdf_time_from_cal(time_var, &calendar);
}
Index: src/base/pdf-time.c
===================================================================
RCS file: /cvsroot/pdf/libgnupdf/src/base/pdf-time.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- src/base/pdf-time.c 24 Jun 2008 23:22:57 -0000 1.1
+++ src/base/pdf-time.c 27 Jun 2008 21:23:51 -0000 1.2
@@ -39,6 +39,7 @@
#define PDF_MINS_PER_DAY 1440
#define PDF_DAYS_IN_YEAR 365
#define PDF_DAYS_IN_LEAP_YEAR 366
+#define PDF_MINIMUM_YEAR 1970
enum pdf_time_cal_type_e {
PDF_TIME_CAL_LOCAL,
@@ -116,6 +117,22 @@
return sum;
}
+static pdf_bool_t
+pdf_time_is_valid_cal_p(const struct pdf_time_cal_s *p_cal_time)
+{
+ return ( ( (p_cal_time == NULL) || \
+ (p_cal_time->year < PDF_MINIMUM_YEAR) || \
+ (p_cal_time->month < PDF_TIME_JANUARY) || \
+ (p_cal_time->month > PDF_TIME_DECEMBER) || \
+ (p_cal_time->day == 0) || \
+ (p_cal_time->day > pdf_time_get_days_in_month(p_cal_time->year,
+ p_cal_time->month))
|| \
+ (p_cal_time->hour >= PDF_HOURS_PER_DAY) || \
+ (p_cal_time->minute >= PDF_MINS_PER_HOUR) || \
+ (p_cal_time->second >= PDF_SECS_PER_MIN) ) ? PDF_FALSE :
PDF_TRUE);
+
+}
+
/* Get Break-Down calendar from pdf_time_t */
static pdf_status_t
@@ -124,13 +141,29 @@
struct pdf_time_cal_s *p_cal_time)
{
/* Based on glibc's __offtime function */
- /*
http://www.google.com/codesearch?hl=en&q=__offtime+package:http://ftp.gnu.org/gnu/glibc/glibc-2.0.6.tar.gz+show:4uegyBj4-9E:ODNa8i3UKHE:ukTdqrHC4hw&sa=N&cd=1&ct=rc&cs_p=http://ftp.gnu.org/gnu/glibc/glibc-2.0.6.tar.gz&cs_f=glibc-2.0.6/time/offtime.c
*/
pdf_i64_t days;
pdf_i64_t aux64;
pdf_i64_t remaining;
pdf_i32_t years;
pdf_i32_t months;
+ pdf_time_t new_time_var;
+
+ /* Duplicate time var */
+ new_time_var = pdf_time_dup(time_var);
+
+ /* If requested local calendar, and we have utc time, remove gmt 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);
+ }
days = pdf_i64_new(0,0);
@@ -139,9 +172,9 @@
/* Get date as days */
- pdf_i64_div_i32_divisor(&days, time_var->seconds, PDF_SECS_PER_DAY);
+ pdf_i64_div_i32_divisor(&days, new_time_var->seconds, PDF_SECS_PER_DAY);
/* Get time in seconds */
- pdf_i64_mod_i32_divisor(&remaining, time_var->seconds, PDF_SECS_PER_DAY);
+ pdf_i64_mod_i32_divisor(&remaining, new_time_var->seconds, PDF_SECS_PER_DAY);
/* Get hours */
pdf_i64_div_i32_divisor(&aux64, remaining, PDF_SECS_PER_HOUR);
@@ -204,7 +237,12 @@
p_cal_time->month = months;
p_cal_time->day = pdf_i64_to_i32(days) + 1;
- return PDF_OK;
+ /* Finally, set gmt offset */
+ p_cal_time->gmt_offset = new_time_var->gmt_offset;
+
+ pdf_time_destroy(new_time_var);
+
+ return (pdf_time_is_valid_cal_p(p_cal_time) ? PDF_OK : PDF_ERROR);
}
@@ -520,13 +558,13 @@
*/
static pdf_status_t
pdf_time_add_cal_span_with_sign (pdf_time_t time_var,
- const struct pdf_time_cal_span_s cal_span,
+ const struct pdf_time_cal_span_s *p_cal_span,
int sign)
{
pdf_status_t status = PDF_ERROR;
/* Check allowed sign values */
- if( (sign == -1) && \
+ if( (sign == -1) || \
(sign == 1) )
{
struct pdf_time_cal_s calendar;
@@ -534,14 +572,14 @@
/* Create Calendar type from the time object */
if(pdf_time_get_utc_cal (time_var, &calendar) == PDF_OK)
{
- pdf_time_calendar_add_days(&calendar, sign * cal_span.days);
- pdf_time_calendar_add_months(&calendar, sign * cal_span.months);
- pdf_time_calendar_add_years(&calendar, sign * cal_span.years);
- pdf_time_calendar_add_hours(&calendar, sign * cal_span.hours);
- pdf_time_calendar_add_minutes(&calendar, sign * cal_span.minutes);
- pdf_time_calendar_add_seconds(&calendar, sign * cal_span.seconds);
+ pdf_time_calendar_add_days(&calendar, sign * p_cal_span->days);
+ pdf_time_calendar_add_months(&calendar, sign * p_cal_span->months);
+ pdf_time_calendar_add_years(&calendar, sign * p_cal_span->years);
+ pdf_time_calendar_add_hours(&calendar, sign * p_cal_span->hours);
+ pdf_time_calendar_add_minutes(&calendar, sign *
p_cal_span->minutes);
+ pdf_time_calendar_add_seconds(&calendar, sign *
p_cal_span->seconds);
- status = pdf_time_from_cal(time_var, calendar);
+ status = pdf_time_from_cal(time_var, &calendar);
}
}
@@ -551,17 +589,17 @@
/* Add the time span represented by cal_span to the text object. */
pdf_status_t
pdf_time_add_cal_span (pdf_time_t time_var,
- const struct pdf_time_cal_span_s cal_span)
+ const struct pdf_time_cal_span_s *p_cal_span)
{
- return pdf_time_add_cal_span_with_sign(time_var, cal_span, 1);
+ return pdf_time_add_cal_span_with_sign(time_var, p_cal_span, 1);
}
/* Substract the time span represented by cal_span from the text object */
pdf_status_t
pdf_time_sub_cal_span (pdf_time_t time_var,
- const struct pdf_time_cal_span_s cal_span)
+ const struct pdf_time_cal_span_s *p_cal_span)
{
- return pdf_time_add_cal_span_with_sign(time_var, cal_span, -1);
+ return pdf_time_add_cal_span_with_sign(time_var, p_cal_span, -1);
}
/* Add the time span contained in time_span to time. As the time span is stored
@@ -611,13 +649,13 @@
/* Set the value of a time variable to a given calendar time. */
pdf_status_t
pdf_time_from_cal (pdf_time_t time_var,
- const struct pdf_time_cal_s cal_time)
+ const struct pdf_time_cal_s *p_cal_time)
{
pdf_i64_t aux;
pdf_i32_t walker;
- if((time_var == NULL) || \
- (cal_time.year < 1970))
+ if( (time_var == NULL) || \
+ (! pdf_time_is_valid_cal_p(p_cal_time)) )
{
PDF_DEBUG_BASE("Invalid arguments received");
return PDF_EBADDATA;
@@ -628,7 +666,7 @@
/* Add days per year until the current year in the calendar */
walker = 1970;
- while(walker < cal_time.year)
+ while(walker < p_cal_time->year)
{
pdf_i64_add_i32(&aux, aux, \
(pdf_time_is_leap_year_p(walker) ? \
@@ -637,11 +675,11 @@
}
/* Add days per month until the current month in the calendar */
- pdf_i64_add_i32(&aux, aux, pdf_time_get_days_before_month(cal_time.year,
- cal_time.month));
+ 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, cal_time.day);
+ pdf_i64_add_i32(&aux, aux, p_cal_time->day);
/* Set date as seconds in the output variable */
pdf_i64_mult_i32(&(time_var->seconds), aux, PDF_SECS_PER_DAY);
@@ -649,15 +687,15 @@
/* Add hours as seconds */
pdf_i64_add_i32(&(time_var->seconds), \
(time_var->seconds), \
- cal_time.hour * PDF_SECS_PER_HOUR);
+ p_cal_time->hour * PDF_SECS_PER_HOUR);
/* Add minutes as seconds */
pdf_i64_add_i32(&(time_var->seconds), \
(time_var->seconds), \
- cal_time.minute * PDF_SECS_PER_MIN);
+ p_cal_time->minute * PDF_SECS_PER_MIN);
/* Finally, add seconds */
pdf_i64_add_i32(&(time_var->seconds), \
(time_var->seconds), \
- cal_time.second);
+ p_cal_time->second);
return PDF_OK;
}
@@ -666,12 +704,26 @@
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 */
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;
}
@@ -786,9 +838,10 @@
if(pdf_time_set_to_current_utc_time(time_var) == PDF_OK)
{
/* And correct time with GMT offset */
- pdf_i64_add_i32(&(time_var->seconds),
+ 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 */
time_var->gmt_offset = pdf_time_context_get_gmt_offset();
return PDF_OK;
@@ -808,7 +861,8 @@
time_t time_now = time(NULL);
if(time_now != -1)
{
- /* At least until 2038 this call will work correctly... */
+ /* At least until 2038 this call will work correctly, even in systems
with
+ * a 32bit time_t */
pdf_i64_assign_quick(&(time_var->seconds), (pdf_i32_t)time_now);
time_var->gmt_offset = 0;
}
@@ -937,14 +991,13 @@
* base time to get the number of seconds, and then that number is stored in
* the resulting calendar span */
pdf_status_t
-pdf_time_add_cal_span_with_base (const struct pdf_time_cal_span_s span1,
- const struct pdf_time_cal_span_s span2,
+pdf_time_add_cal_span_with_base (const struct pdf_time_cal_span_s *p_span1,
+ const struct pdf_time_cal_span_s *p_span2,
const pdf_time_t base_time,
struct pdf_time_cal_span_s *p_result)
{
pdf_time_t time1;
pdf_time_t time2;
- pdf_i32_t cmp_ret = 0;
pdf_status_t ret_code = PDF_ERROR;
time1 = pdf_time_dup(base_time);
@@ -952,8 +1005,10 @@
if( (time1 != NULL) && \
(time2 != NULL) && \
- (pdf_time_add_cal_span(time1, span1) == PDF_OK) && \
- (pdf_time_add_cal_span(time2, span2) == PDF_OK) )
+ (p_span1 != NULL) && \
+ (p_span2 != NULL) && \
+ (pdf_time_add_cal_span(time1, p_span1) == PDF_OK) && \
+ (pdf_time_add_cal_span(time2, p_span2) == PDF_OK) )
{
pdf_time_span_t span_time1;
pdf_time_span_t span_time2;
@@ -1005,8 +1060,8 @@
/* Compare two calendar spans previously resolved with a given base time. */
pdf_i32_t
-pdf_time_cal_span_cmp (const struct pdf_time_cal_span_s span1,
- const struct pdf_time_cal_span_s span2,
+pdf_time_cal_span_cmp (const struct pdf_time_cal_span_s *p_span1,
+ const struct pdf_time_cal_span_s *p_span2,
const pdf_time_t base_time,
pdf_status_t *p_ret_code)
{
@@ -1022,8 +1077,10 @@
if( (time1 != NULL) && \
(time2 != NULL) && \
- (pdf_time_add_cal_span(time1, span1) == PDF_OK) && \
- (pdf_time_add_cal_span(time2, span2) == PDF_OK) )
+ (p_span1 != NULL) && \
+ (p_span2 != NULL) && \
+ (pdf_time_add_cal_span(time1, p_span1) == PDF_OK) && \
+ (pdf_time_add_cal_span(time2, p_span2) == PDF_OK) )
{
cmp_ret = pdf_time_cmp(time1, time2);
ret_code = PDF_OK;
@@ -1042,8 +1099,8 @@
/* Compute the difference between two calendar spans relative to a given base
* time and store it in a given calendar span. */
pdf_status_t
-pdf_time_cal_span_diff (const struct pdf_time_cal_span_s span1,
- const struct pdf_time_cal_span_s span2,
+pdf_time_cal_span_diff (const struct pdf_time_cal_span_s *p_span1,
+ const struct pdf_time_cal_span_s *p_span2,
const pdf_time_t base_time,
struct pdf_time_cal_span_s *p_result)
{
Index: src/base/pdf-time.h
===================================================================
RCS file: /cvsroot/pdf/libgnupdf/src/base/pdf-time.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- src/base/pdf-time.h 24 Jun 2008 23:22:58 -0000 1.1
+++ src/base/pdf-time.h 27 Jun 2008 21:23:51 -0000 1.2
@@ -135,12 +135,12 @@
/* Add the time span represented by cal_span to the text object */
pdf_status_t
pdf_time_add_cal_span (pdf_time_t time_var,
- const struct pdf_time_cal_span_s cal_span);
+ const struct pdf_time_cal_span_s *p_cal_span);
/* Substract the time span represented by cal_span from the text object */
pdf_status_t
pdf_time_sub_cal_span (pdf_time_t time_var,
- const struct pdf_time_cal_span_s cal_span);
+ const struct pdf_time_cal_span_s *p_cal_span);
/* Add the time span contained in time_span to time. */
pdf_status_t
@@ -165,7 +165,7 @@
/* Set the value of a time variable to a given calendar time. */
pdf_status_t
pdf_time_from_cal (pdf_time_t time_var,
- const struct pdf_time_cal_s cal_time);
+ const struct pdf_time_cal_s *p_cal_time);
/* Set the local time offset of time to the one used by the operating system.
*/
pdf_status_t
@@ -299,23 +299,23 @@
* has more days than another) the calendar spans are first resolved from a
* base time. */
pdf_status_t
-pdf_time_add_cal_span_with_base (const struct pdf_time_cal_span_s span1,
- const struct pdf_time_cal_span_s span2,
+pdf_time_add_cal_span_with_base (const struct pdf_time_cal_span_s *p_span1,
+ const struct pdf_time_cal_span_s *p_span2,
const pdf_time_t base_time,
struct pdf_time_cal_span_s *p_result);
/* Compare two calendar spans previously resolved with a given base time. */
pdf_i32_t
-pdf_time_cal_span_cmp (const struct pdf_time_cal_span_s span1,
- const struct pdf_time_cal_span_s span2,
+pdf_time_cal_span_cmp (const struct pdf_time_cal_span_s *p_span1,
+ const struct pdf_time_cal_span_s *p_span2,
const pdf_time_t base_time,
pdf_status_t *p_ret_code);
/* Compute the difference between two calendar spans relative to a given base
* time and store it in a given calendar span. */
pdf_status_t
-pdf_time_cal_span_diff (const struct pdf_time_cal_span_s span1,
- const struct pdf_time_cal_span_s span2,
+pdf_time_cal_span_diff (const struct pdf_time_cal_span_s *p_span1,
+ const struct pdf_time_cal_span_s *p_span2,
const pdf_time_t base_time,
struct pdf_time_cal_span_s *p_result);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [pdf-devel] libgnupdf ChangeLog doc/gnupdf.texi src/base/pd...,
Aleksander Morgado <=