Skip to content

Commit

Permalink
refactor date:precision flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Jun 19, 2022
1 parent 68fb3c5 commit 6df26f2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 42 deletions.
1 change: 0 additions & 1 deletion MagickCore/magick.c
Expand Up @@ -1594,7 +1594,6 @@ MagickExport void MagickCoreGenesis(const char *path,
#endif
(void) RegistryComponentGenesis();
(void) MonitorComponentGenesis();
(void) TimerComponentGenesis();
magickcore_instantiated=MagickTrue;
UnlockMagickMutex();
}
Expand Down
4 changes: 4 additions & 0 deletions MagickCore/registry.c
Expand Up @@ -51,6 +51,8 @@
#include "MagickCore/registry-private.h"
#include "MagickCore/splay-tree.h"
#include "MagickCore/string_.h"
#include "MagickCore/string-private.h"
#include "MagickCore/timer-private.h"
#include "MagickCore/utility.h"

/*
Expand Down Expand Up @@ -475,6 +477,8 @@ MagickExport MagickBooleanType SetImageRegistry(const RegistryType type,
const char
*string;

if (LocaleCompare(key,"date:precision") == 0)
SetMagickDatePrecision(StringToInteger(value));
string=(const char *) value;
clone_value=(void *) ConstantString(string);
break;
Expand Down
4 changes: 2 additions & 2 deletions MagickCore/timer-private.h
Expand Up @@ -57,8 +57,8 @@ static inline void GetMagickLocaltime(const time_t *timep,struct tm *result)
extern MagickExport time_t
GetMagickTime(void);

extern MagickPrivate MagickBooleanType
TimerComponentGenesis(void);
extern MagickPrivate void
SetMagickDatePrecision(const unsigned long);

#if defined(__cplusplus) || defined(c_plusplus)
}
Expand Down
79 changes: 40 additions & 39 deletions MagickCore/timer.c
Expand Up @@ -269,6 +269,19 @@ MagickExport ssize_t FormatMagickTime(const time_t time,const size_t length,
utc_time;

assert(timestamp != (char *) NULL);
if (date_precision == -1)
{
char
*limit;

date_precision=0;
limit=GetEnvironmentValue("MAGICK_DATE_PRECISION");
if (limit != (char *) NULL)
{
date_precision=StringToInteger(limit);
limit=DestroyString(limit);
}
}
GetMagickUTCtime(&time,&utc_time);
count=FormatLocaleString(timestamp,length,
"%04d-%02d-%02dT%02d:%02d:%02d%+03d:00",utc_time.tm_year+1900,
Expand Down Expand Up @@ -467,6 +480,33 @@ MagickExport void ResetTimer(TimerInfo *time_info)
% %
% %
% %
% S e t M a g i c k D a t e P r e c i s i o n %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% SetMagickDatePrecision() sets the pseudo-random number generator secret key.
%
% The format of the SetMagickDatePrecision method is:
%
% void SetMagickDatePrecision(const unsigned long precision)
%
% A description of each parameter follows:
%
% o key: the date precision.
%
*/
MagickPrivate void SetMagickDatePrecision(const unsigned long precision)
{
date_precision=precision;
}

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
+ S t a r t T i m e r %
% %
% %
Expand Down Expand Up @@ -545,45 +585,6 @@ static void StopTimer(TimerInfo *time_info)
}
time_info->state=StoppedTimerState;
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
+ T i m e r C o m p o n e n t G e n e s i s %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% TimerComponentGenesis() instantiates the timer component.
%
% The format of the TimerComponentGenesis method is:
%
% MagickBooleanTimer TimerComponentGenesis(void)
%
*/
MagickPrivate MagickBooleanType TimerComponentGenesis(void)
{
char
*limit;

ExceptionInfo
*exception = AcquireExceptionInfo();

date_precision=0;
limit=(char *) GetImageRegistry(StringRegistryType,"date:precision",
exception);
exception=DestroyExceptionInfo(exception);
if (limit == (char *) NULL)
limit=GetEnvironmentValue("MAGICK_DATE_PRECISION");
if (limit != (char *) NULL)
{
date_precision=StringToInteger(limit);
limit=DestroyString(limit);
}
return(MagickTrue);
}

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down

0 comments on commit 6df26f2

Please sign in to comment.