From 08936924a7a4b1541ee5f9778cae6bffef1767b3 Mon Sep 17 00:00:00 2001 From: Peter Verthez Date: Mon, 30 Dec 2002 09:32:28 +0000 Subject: [PATCH] New function to update timestamp. --- gom/gom_internal.h | 4 ++++ gom/gom_modify.c | 32 ++++++++++++++++++++++++++++++++ gom/header.c | 10 ++++++++++ include/gom.h | 3 +++ 4 files changed, 49 insertions(+) diff --git a/gom/gom_internal.h b/gom/gom_internal.h index 46c42a1..3b482f2 100644 --- a/gom/gom_internal.h +++ b/gom/gom_internal.h @@ -27,6 +27,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H #include #endif @@ -109,6 +110,9 @@ void def_elt_end(Gedcom_elt elt, Gedcom_ctxt parent, Gedcom_ctxt self, Gedcom_val parsed_value); void set_xref_type(struct xref_value *xr, const char* str); +int update_date(struct date_value** dv, struct tm* tm_ptr); +int update_time(char** tv, struct tm* tm_ptr); + /* Doubly-linked list, but last rec->next is NULL (doesn't go to first rec) */ #define LINK_CHAIN_ELT(STRUCTTYPE, FIRSTVAL, VAL) \ { \ diff --git a/gom/gom_modify.c b/gom/gom_modify.c index 3da2fa8..bc65a3a 100644 --- a/gom/gom_modify.c +++ b/gom/gom_modify.c @@ -23,6 +23,7 @@ #include #include +#include #include "utf8tools.h" #include "gom.h" #include "gom_internal.h" @@ -77,3 +78,34 @@ char* gom_set_string_for_locale(char** data, const char* locale_str) return result; } + +int update_date(struct date_value** dv, struct tm* tm_ptr) +{ + int result; + struct date_value* dval = gedcom_new_date_value(NULL); + dval->type = DV_NO_MODIFIER; + dval->date1.cal = CAL_GREGORIAN; + dval->date1.day = tm_ptr->tm_mday; + dval->date1.month = tm_ptr->tm_mon + 1; + dval->date1.year = tm_ptr->tm_year + 1900; + result = gedcom_normalize_date(DI_FROM_NUMBERS, dval); + + if (result == 0) { + if (*dv) free(*dv); + *dv = dval; + } + return result; +} + +int update_time(char** tv, struct tm* tm_ptr) +{ + char tval[16]; + sprintf(tval, "%02d:%02d:%02d", + tm_ptr->tm_hour, tm_ptr->tm_min, tm_ptr->tm_sec); + + if (gom_set_string(tv, tval)) + return 0; + else + return 1; +} + diff --git a/gom/header.c b/gom/header.c index 18dc38c..122c780 100644 --- a/gom/header.c +++ b/gom/header.c @@ -21,6 +21,7 @@ /* $Id$ */ /* $Name$ */ +#include #include "header.h" #include "submission.h" #include "submitter.h" @@ -163,6 +164,15 @@ struct header* gom_get_header() return &gom_header; } +int gom_header_update_timestamp(time_t t) +{ + int result = 0; + struct tm *tm_ptr = localtime(&t); + result |= update_date(&gom_header.date, tm_ptr); + result |= update_time(&gom_header.time, tm_ptr); + return result; +} + int write_header(Gedcom_write_hndl hndl) { int result = 0; diff --git a/include/gom.h b/include/gom.h index 5a706cc..0c68d30 100644 --- a/include/gom.h +++ b/include/gom.h @@ -25,6 +25,7 @@ #define __GEDCOM_GOM_H #include "gedcom.h" +#include #ifdef __cplusplus extern "C" { @@ -422,6 +423,8 @@ int gom_new_model(); int gom_write_file(const char* file_name, int *total_conv_fails); struct header* gom_get_header(); +int gom_header_update_timestamp(time_t t); + struct submission* gom_get_submission(); struct family* gom_get_first_family(); -- 2.30.2