static void write_tIME_chunk(Image *image,png_struct *ping,png_info *info,
const char *date,ExceptionInfo *exception)
{
+ const char
+ *timestamp;
+
+ int
+ ret;
+
unsigned int
day,
hour,
ptime;
if (date == (const char *) NULL)
- {
- const char
- *timestamp;
-
- timestamp=GetImageProperty(image,"date:modify",exception);
- if (sscanf(timestamp,"%d-%d-%dT%d:%d:%d%d:%d",&year,&month,&day,&hour,
- &minute, &second, &addhours, &addminutes) != 8)
- {
- (void) ThrowMagickException(exception,GetMagickModule(),CoderError,
- "Invalid date format specified for png:tIME","`%s'",
- image->filename);
- return;
- }
- }
+ timestamp=GetImageProperty(image,"date:modify",exception);
else
- {
- if (sscanf(date,"%d-%d-%dT%d:%d:%d%d:%d",&year,&month,&day,&hour,
- &minute, &second, &addhours, &addminutes) != 8)
- {
- (void) ThrowMagickException(exception,GetMagickModule(),CoderError,
- "Invalid date format specified for png:tIME","`%s'",
- image->filename);
- return;
- }
- }
- ptime.year=(png_uint_16) year;
- ptime.month=(png_byte) month;
- ptime.day=(png_byte) day;
- ptime.hour=(png_byte) hour+addhours;
- ptime.minute=(png_byte) minute+addminutes;
- ptime.second=(png_byte) second;
- if (ptime.minute > 60)
- {
- ptime.hour++;
- ptime.minute-=60;
- }
- if (ptime.hour > 24)
- {
- ptime.day ++;
- ptime.hour -=24;
- }
- /* To do: fix this for leap years */
- if (ptime.day > 31 || (ptime.month == 2 && ptime.day > 28) ||
- ((ptime.month == 4 || ptime.month == 6 || ptime.month == 9 ||
- ptime.month == 11) && ptime.day > 30))
- {
- ptime.month++;
- ptime.day = 1;
- }
- if (ptime.month > 12)
- {
- ptime.year++;
- ptime.month=1;
- }
- png_set_tIME(ping,info,&ptime);
+ timestamp=date;
+
+ LogMagickEvent(CoderEvent,GetMagickModule(),
+ " Writing tIME chunk: timestamp property is %30s\n",timestamp);
+ ret=sscanf(timestamp,"%d-%d-%dT%d:%d:%d",&year,&month,&day,&hour,
+ &minute, &second);
+ if (ret < 6)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),CoderError,
+ "Invalid date format specified for png:tIME","`%s'",
+ image->filename);
+ return;
+ }
+ addhours=0;
+ addminutes=0;
+ ret=sscanf(timestamp,"%d-%d-%dT%d:%d:%d%d:%d",&year,&month,&day,&hour,
+ &minute, &second, &addhours, &addminutes);
+ if (ret < 6)
+ {
+ LogMagickEvent(CoderEvent,GetMagickModule(),
+ " Invalid timestamp is %60s\n",timestamp);
+ (void) ThrowMagickException(exception,GetMagickModule(),CoderError,
+ "Invalid date format specified for png:tIME","`%s'",
+ image->filename);
+ return;
+ }
+ ptime.year=(png_uint_16) year;
+ ptime.month=(png_byte) month;
+ ptime.day=(png_byte) day;
+ ptime.hour=(png_byte) hour+addhours;
+ ptime.minute=(png_byte) minute+addminutes;
+ ptime.second=(png_byte) second;
+ if (ptime.minute > 60)
+ {
+ ptime.hour++;
+ ptime.minute-=60;
+ }
+ if (ptime.hour > 24)
+ {
+ ptime.day ++;
+ ptime.hour -=24;
+ }
+ /* To do: fix this for leap years */
+ if (ptime.day > 31 || (ptime.month == 2 && ptime.day > 28) ||
+ ((ptime.month == 4 || ptime.month == 6 || ptime.month == 9 ||
+ ptime.month == 11) && ptime.day > 30))
+ {
+ ptime.month++;
+ ptime.day = 1;
+ }
+ if (ptime.month > 12)
+ {
+ ptime.year++;
+ ptime.month=1;
+ }
+ png_set_tIME(ping,info,&ptime);
}
#endif