Skip to content

Commit

Permalink
Set last modified date to current day (in local tz)
Browse files Browse the repository at this point in the history
  • Loading branch information
thbeu committed Mar 9, 2024
1 parent 644559c commit 4fea351
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion dbfopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@
#include "shapefil_private.h"

#include <math.h>
#include <time.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

/* Check for POSIX in unistd.h */
#if defined(__unix__) || defined(__linux__) || defined(__APPLE_CC__)
#include <unistd.h>
#endif
#if !defined(_POSIX_) && defined(_POSIX_VERSION)
#define _POSIX_ 1
#endif

#ifdef USE_CPL
#include "cpl_string.h"
#else
Expand Down Expand Up @@ -291,6 +300,30 @@ void SHPAPI_CALL DBFSetLastModifiedDate(DBFHandle psDBF, int nYYSince1900,
psDBF->nUpdateDay = nDD;
}

/************************************************************************/
/* DBFSetLastModifiedDateToday() */
/************************************************************************/

static void DBFSetLastModifiedDateToday(DBFHandle psDBF)
{
struct tm *tlocal;
time_t calendarTime;
#if defined(_POSIX_) || (defined(_MSC_VER) && _MSC_VER >= 1400)
struct tm tres;
#endif
time(&calendarTime);
#if defined(_POSIX_)
tlocal = localtime_r(&calendarTime, &tres);
#elif defined(_MSC_VER) && _MSC_VER >= 1400
localtime_s(&tres, &calendarTime);
tlocal = &tres;
#else
tlocal = localtime(&calendarTime);
#endif
DBFSetLastModifiedDate(psDBF, tlocal->tm_year, tlocal->tm_mon + 1,
tlocal->tm_mday);
}

/************************************************************************/
/* DBFOpen() */
/* */
Expand Down Expand Up @@ -699,7 +732,7 @@ DBFHandle SHPAPI_CALL DBFCreateLL(const char *pszFilename,
STATIC_CAST(char *, malloc(strlen(pszCodePage) + 1));
strcpy(psDBF->pszCodePage, pszCodePage);
}
DBFSetLastModifiedDate(psDBF, 95, 7, 26); /* dummy date */
DBFSetLastModifiedDateToday(psDBF);

DBFSetWriteEndOfFileChar(psDBF, TRUE);

Expand Down

0 comments on commit 4fea351

Please sign in to comment.