/// <summary>
        /// Sets the local time zone without touching any other Any existing time zone value is replaced,
        /// the other date/time fields are not adjusted in any way.
        /// </summary>
        /// <param name="dateTime">the <code>XMPDateTime</code> variable containing the value to be modified.
        ///     </param>
        /// <returns>Returns an updated <code>XMPDateTime</code>-object.</returns>
        public static XMPDateTime SetLocalTimeZone(XMPDateTime dateTime)
        {
            XMPCalendar cal = dateTime.GetCalendar();

            cal.SetTimeZone(TimeZone.CurrentTimeZone);
            return(new XMPDateTimeImpl(cal));
        }
Example #2
0
        /// <summary>Fixes the GPS Timestamp in EXIF.</summary>
        /// <param name="exifSchema">the EXIF schema node</param>
        /// <exception cref="iText.Kernel.XMP.XMPException">Thrown if the date conversion fails.
        ///     </exception>
        private static void FixGPSTimeStamp(XMPNode exifSchema)
        {
            // Note: if dates are not found the convert-methods throws an exceptions,
            //       and this methods returns.
            XMPNode gpsDateTime = XMPNodeUtils.FindChildNode(exifSchema, "exif:GPSTimeStamp", false);

            if (gpsDateTime == null)
            {
                return;
            }

            try {
                XMPDateTime binGpsStamp = XMPUtils.ConvertToDate(gpsDateTime.GetValue());
                if (binGpsStamp.GetYear() != 0 || binGpsStamp.GetMonth() != 0 || binGpsStamp.GetDay() != 0)
                {
                    return;
                }

                XMPNode otherDate = XMPNodeUtils.FindChildNode(exifSchema, "exif:DateTimeOriginal", false);
                otherDate = otherDate ?? XMPNodeUtils.FindChildNode(exifSchema, "exif:DateTimeDigitized", false);

                XMPDateTime binOtherDate = XMPUtils.ConvertToDate(otherDate.GetValue());
                XMPCalendar cal          = binGpsStamp.GetCalendar();
                DateTime    dt           = new DateTime(binOtherDate.GetYear(), binOtherDate.GetMonth(), binOtherDate.GetDay(),
                                                        cal.GetDateTime().Hour, cal.GetDateTime().Minute, cal.GetDateTime().Second, cal.GetDateTime().Millisecond);
                cal.SetDateTime(dt);
                binGpsStamp = new XMPDateTimeImpl(cal);
                gpsDateTime.SetValue(XMPUtils.ConvertFromDate(binGpsStamp));
            }
            catch (XMPException) {
            }
        }
 /// <summary>Make sure a time is UTC.</summary>
 /// <remarks>
 /// Make sure a time is UTC. If the time zone is not UTC, the time is
 /// adjusted and the time zone set to be UTC.
 /// </remarks>
 /// <param name="dateTime">
 /// the <code>XMPDateTime</code> variable containing the time to
 /// be modified.
 /// </param>
 /// <returns>Returns an updated <code>XMPDateTime</code>-object.</returns>
 public static XMPDateTime ConvertToUTCTime(XMPDateTime dateTime)
 {
     long timeInMillis = dateTime.GetCalendar().GetTimeInMillis();
     Sharpen.GregorianCalendar cal = new Sharpen.GregorianCalendar(Utc);
     cal.SetGregorianChange(Sharpen.Extensions.CreateDate(long.MinValue));
     cal.SetTimeInMillis(timeInMillis);
     return new XMPDateTimeImpl(cal);
 }
 /// <summary>Make sure a time is local.</summary>
 /// <remarks>
 /// Make sure a time is local. If the time zone is not the local zone, the time is adjusted and
 /// the time zone set to be local.
 /// </remarks>
 /// <param name="dateTime">the <code>XMPDateTime</code> variable containing the time to be modified.</param>
 /// <returns>Returns an updated <code>XMPDateTime</code>-object.</returns>
 public static XMPDateTime ConvertToLocalTime(XMPDateTime dateTime)
 {
     long timeInMillis = dateTime.GetCalendar().GetTimeInMillis();
     // has automatically local timezone
     Sharpen.GregorianCalendar cal = new Sharpen.GregorianCalendar();
     cal.SetTimeInMillis(timeInMillis);
     return new XMPDateTimeImpl(cal);
 }
        /// <summary>Make sure a time is UTC.</summary>
        /// <remarks>
        /// Make sure a time is UTC. If the time zone is not UTC, the time is
        /// adjusted and the time zone set to be UTC.
        /// </remarks>
        /// <param name="dateTime">
        /// the <code>XMPDateTime</code> variable containing the time to
        /// be modified.
        /// </param>
        /// <returns>Returns an updated <code>XMPDateTime</code>-object.</returns>
        public static XMPDateTime ConvertToUTCTime(XMPDateTime dateTime)
        {
            long        timeInMillis = dateTime.GetCalendar().GetTimeInMillis();
            XMPCalendar cal          = new XMPCalendar();

            cal.SetTimeInMillis(timeInMillis);
            return(new XMPDateTimeImpl(cal));
        }
        /// <summary>Make sure a time is local.</summary>
        /// <remarks>
        /// Make sure a time is local. If the time zone is not the local zone, the time is adjusted and
        /// the time zone set to be local.
        /// </remarks>
        /// <param name="dateTime">the <code>XMPDateTime</code> variable containing the time to be modified.
        ///     </param>
        /// <returns>Returns an updated <code>XMPDateTime</code>-object.</returns>
        public static XMPDateTime ConvertToLocalTime(XMPDateTime dateTime)
        {
            long timeInMillis = dateTime.GetCalendar().GetTimeInMillis();
            // has automatically local timezone
            XMPCalendar cal = new XMPCalendar();

            cal.SetTimeInMillis(timeInMillis);
            return(new XMPDateTimeImpl(cal));
        }
Example #7
0
        /// <summary>Make sure a time is UTC.</summary>
        /// <remarks>
        /// Make sure a time is UTC. If the time zone is not UTC, the time is
        /// adjusted and the time zone set to be UTC.
        /// </remarks>
        /// <param name="dateTime">
        /// the <code>XMPDateTime</code> variable containing the time to
        /// be modified.
        /// </param>
        /// <returns>Returns an updated <code>XMPDateTime</code>-object.</returns>
        public static XMPDateTime ConvertToUTCTime(XMPDateTime dateTime)
        {
            long timeInMillis = dateTime.GetCalendar().GetTimeInMillis();

            Sharpen.GregorianCalendar cal = new Sharpen.GregorianCalendar(Utc);
            cal.SetGregorianChange(Sharpen.Extensions.CreateDate(long.MinValue));
            cal.SetTimeInMillis(timeInMillis);
            return(new XMPDateTimeImpl(cal));
        }
 /// <summary>
 /// Sets the local time zone without touching any other Any existing time zone value is replaced,
 /// the other date/time fields are not adjusted in any way.
 /// </summary>
 /// <param name="dateTime">the <code>XMPDateTime</code> variable containing the value to be modified.</param>
 /// <returns>Returns an updated <code>XMPDateTime</code>-object.</returns>
 public static XMPDateTime SetLocalTimeZone(XMPDateTime dateTime)
 {
     Sharpen.Calendar cal = dateTime.GetCalendar();
     cal.SetTimeZone(System.TimeZoneInfo.Local);
     return new XMPDateTimeImpl(cal);
 }
Example #9
0
 /// <summary>
 /// Sets the local time zone without touching any other Any existing time zone value is replaced,
 /// the other date/time fields are not adjusted in any way.
 /// </summary>
 /// <param name="dateTime">the <code>XMPDateTime</code> variable containing the value to be modified.</param>
 /// <returns>Returns an updated <code>XMPDateTime</code>-object.</returns>
 public static XMPDateTime SetLocalTimeZone(XMPDateTime dateTime)
 {
     Sharpen.Calendar cal = dateTime.GetCalendar();
     cal.SetTimeZone(System.TimeZoneInfo.Local);
     return(new XMPDateTimeImpl(cal));
 }
 /// <summary>Converts a <code>Calendar</code> into an ISO 8601 string.</summary>
 /// <remarks>
 /// Converts a <code>Calendar</code> into an ISO 8601 string.
 /// Format a date according to ISO 8601 and http://www.w3.org/TR/NOTE-datetime:
 /// <ul>
 /// <li>YYYY
 /// <li>YYYY-MM
 /// <li>YYYY-MM-DD
 /// <li>YYYY-MM-DDThh:mmTZD
 /// <li>YYYY-MM-DDThh:mm:ssTZD
 /// <li>YYYY-MM-DDThh:mm:ss.sTZD
 /// </ul>
 /// Data fields:
 /// <ul>
 /// <li>YYYY = four-digit year
 /// <li>MM	 = two-digit month (01=January, etc.)
 /// <li>DD	 = two-digit day of month (01 through 31)
 /// <li>hh	 = two digits of hour (00 through 23)
 /// <li>mm	 = two digits of minute (00 through 59)
 /// <li>ss	 = two digits of second (00 through 59)
 /// <li>s	 = one or more digits representing a decimal fraction of a second
 /// <li>TZD	 = time zone designator (Z or +hh:mm or -hh:mm)
 /// </ul>
 /// <p>
 /// <em>Note:</em> ISO 8601 does not seem to allow years less than 1000 or greater than 9999.
 /// We allow any year, even negative ones. The year is formatted as "%.4d".<p>
 /// <em>Note:</em> Fix for bug 1269463 (silently fix out of range values) included in parsing.
 /// The quasi-bogus "time only" values from Photoshop CS are not supported.
 /// </remarks>
 /// <param name="dateTime">an XMPDateTime-object.</param>
 /// <returns>Returns an ISO 8601 string.</returns>
 public static string Render(XMPDateTime dateTime)
 {
     StringBuilder buffer = new StringBuilder();
     if (dateTime.HasDate())
     {
         // year is rendered in any case, even 0000
         DecimalFormat df = new DecimalFormat("0000", new DecimalFormatSymbols(Sharpen.Extensions.GetEnglishCulture()));
         buffer.Append(df.Format(dateTime.GetYear()));
         if (dateTime.GetMonth() == 0)
         {
             return buffer.ToString();
         }
         // month
         df.ApplyPattern("'-'00");
         buffer.Append(df.Format(dateTime.GetMonth()));
         if (dateTime.GetDay() == 0)
         {
             return buffer.ToString();
         }
         // day
         buffer.Append(df.Format(dateTime.GetDay()));
         // time, rendered if any time field is not zero
         if (dateTime.HasTime())
         {
             // hours and minutes
             buffer.Append('T');
             df.ApplyPattern("00");
             buffer.Append(df.Format(dateTime.GetHour()));
             buffer.Append(':');
             buffer.Append(df.Format(dateTime.GetMinute()));
             // seconds and nanoseconds
             if (dateTime.GetSecond() != 0 || dateTime.GetNanoSecond() != 0)
             {
                 double seconds = dateTime.GetSecond() + dateTime.GetNanoSecond() / 1e9d;
                 df.ApplyPattern(":00.#########");
                 buffer.Append(df.Format(seconds));
             }
             // time zone
             if (dateTime.HasTimeZone())
             {
                 // used to calculate the time zone offset incl. Daylight Savings
                 long timeInMillis = dateTime.GetCalendar().GetTimeInMillis();
                 int offset = dateTime.GetTimeZone().GetOffset(timeInMillis);
                 if (offset == 0)
                 {
                     // UTC
                     buffer.Append('Z');
                 }
                 else
                 {
                     int thours = offset / 3600000;
                     int tminutes = Math.Abs(offset % 3600000 / 60000);
                     df.ApplyPattern("+00;-00");
                     buffer.Append(df.Format(thours));
                     df.ApplyPattern(":00");
                     buffer.Append(df.Format(tminutes));
                 }
             }
         }
     }
     return buffer.ToString();
 }
 /// <summary>Converts a <code>Calendar</code> into an ISO 8601 string.</summary>
 /// <remarks>
 /// Converts a <code>Calendar</code> into an ISO 8601 string.
 /// Format a date according to ISO 8601 and http://www.w3.org/TR/NOTE-datetime:
 /// <ul>
 /// <li>YYYY
 /// <li>YYYY-MM
 /// <li>YYYY-MM-DD
 /// <li>YYYY-MM-DDThh:mmTZD
 /// <li>YYYY-MM-DDThh:mm:ssTZD
 /// <li>YYYY-MM-DDThh:mm:ss.sTZD
 /// </ul>
 /// Data fields:
 /// <ul>
 /// <li>YYYY = four-digit year
 /// <li>MM	 = two-digit month (01=January, etc.)
 /// <li>DD	 = two-digit day of month (01 through 31)
 /// <li>hh	 = two digits of hour (00 through 23)
 /// <li>mm	 = two digits of minute (00 through 59)
 /// <li>ss	 = two digits of second (00 through 59)
 /// <li>s	 = one or more digits representing a decimal fraction of a second
 /// <li>TZD	 = time zone designator (Z or +hh:mm or -hh:mm)
 /// </ul>
 /// <p>
 /// <em>Note:</em> ISO 8601 does not seem to allow years less than 1000 or greater than 9999.
 /// We allow any year, even negative ones. The year is formatted as "%.4d".<p>
 /// <em>Note:</em> Fix for bug 1269463 (silently fix out of range values) included in parsing.
 /// The quasi-bogus "time only" values from Photoshop CS are not supported.
 /// </remarks>
 /// <param name="dateTime">an XMPDateTime-object.</param>
 /// <returns>Returns an ISO 8601 string.</returns>
 public static String Render(XMPDateTime dateTime)
 {
     return(dateTime.GetCalendar().GetDateTime().ToString("s"));
 }
        /// <summary>Converts a <code>Calendar</code> into an ISO 8601 string.</summary>
        /// <remarks>
        /// Converts a <code>Calendar</code> into an ISO 8601 string.
        /// Format a date according to ISO 8601 and http://www.w3.org/TR/NOTE-datetime:
        /// <ul>
        /// <li>YYYY
        /// <li>YYYY-MM
        /// <li>YYYY-MM-DD
        /// <li>YYYY-MM-DDThh:mmTZD
        /// <li>YYYY-MM-DDThh:mm:ssTZD
        /// <li>YYYY-MM-DDThh:mm:ss.sTZD
        /// </ul>
        /// Data fields:
        /// <ul>
        /// <li>YYYY = four-digit year
        /// <li>MM	 = two-digit month (01=January, etc.)
        /// <li>DD	 = two-digit day of month (01 through 31)
        /// <li>hh	 = two digits of hour (00 through 23)
        /// <li>mm	 = two digits of minute (00 through 59)
        /// <li>ss	 = two digits of second (00 through 59)
        /// <li>s	 = one or more digits representing a decimal fraction of a second
        /// <li>TZD	 = time zone designator (Z or +hh:mm or -hh:mm)
        /// </ul>
        /// <p>
        /// <em>Note:</em> ISO 8601 does not seem to allow years less than 1000 or greater than 9999.
        /// We allow any year, even negative ones. The year is formatted as "%.4d".<p>
        /// <em>Note:</em> Fix for bug 1269463 (silently fix out of range values) included in parsing.
        /// The quasi-bogus "time only" values from Photoshop CS are not supported.
        /// </remarks>
        /// <param name="dateTime">an XMPDateTime-object.</param>
        /// <returns>Returns an ISO 8601 string.</returns>
        public static string Render(XMPDateTime dateTime)
        {
            StringBuilder buffer = new StringBuilder();

            if (dateTime.HasDate())
            {
                // year is rendered in any case, even 0000
                DecimalFormat df = new DecimalFormat("0000", new DecimalFormatSymbols(Sharpen.Extensions.GetEnglishCulture()));
                buffer.Append(df.Format(dateTime.GetYear()));
                if (dateTime.GetMonth() == 0)
                {
                    return(buffer.ToString());
                }
                // month
                df.ApplyPattern("'-'00");
                buffer.Append(df.Format(dateTime.GetMonth()));
                if (dateTime.GetDay() == 0)
                {
                    return(buffer.ToString());
                }
                // day
                buffer.Append(df.Format(dateTime.GetDay()));
                // time, rendered if any time field is not zero
                if (dateTime.HasTime())
                {
                    // hours and minutes
                    buffer.Append('T');
                    df.ApplyPattern("00");
                    buffer.Append(df.Format(dateTime.GetHour()));
                    buffer.Append(':');
                    buffer.Append(df.Format(dateTime.GetMinute()));
                    // seconds and nanoseconds
                    if (dateTime.GetSecond() != 0 || dateTime.GetNanoSecond() != 0)
                    {
                        double seconds = dateTime.GetSecond() + dateTime.GetNanoSecond() / 1e9d;
                        df.ApplyPattern(":00.#########");
                        buffer.Append(df.Format(seconds));
                    }
                    // time zone
                    if (dateTime.HasTimeZone())
                    {
                        // used to calculate the time zone offset incl. Daylight Savings
                        long timeInMillis = dateTime.GetCalendar().GetTimeInMillis();
                        int  offset       = dateTime.GetTimeZone().GetOffset(timeInMillis);
                        if (offset == 0)
                        {
                            // UTC
                            buffer.Append('Z');
                        }
                        else
                        {
                            int thours   = offset / 3600000;
                            int tminutes = Math.Abs(offset % 3600000 / 60000);
                            df.ApplyPattern("+00;-00");
                            buffer.Append(df.Format(thours));
                            df.ApplyPattern(":00");
                            buffer.Append(df.Format(tminutes));
                        }
                    }
                }
            }
            return(buffer.ToString());
        }
Example #13
0
		/// <summary>
		/// Evaluates a raw node value to the given value type, apply special
		/// conversions for defined types in XMP.
		/// </summary>
		/// <param name="valueType">an int indicating the value type</param>
		/// <param name="propNode">the node containing the value</param>
		/// <returns>Returns a literal value for the node.</returns>
		/// <exception cref="iText.Kernel.XMP.XMPException">
		/// if the value of <code>propNode</code> is <code>null</code> or empty or the conversion fails.
		/// </exception>
		private Object EvaluateNodeValue(int valueType, XMPNode propNode)
		{
			Object value;
			String rawValue = propNode.GetValue();
			switch (valueType)
			{
				case VALUE_BOOLEAN:
				{
					value = XMPUtils.ConvertToBoolean(rawValue);
					break;
				}

				case VALUE_INTEGER:
				{
					value = XMPUtils.ConvertToInteger(rawValue);
					break;
				}

				case VALUE_LONG:
				{
					value = XMPUtils.ConvertToLong(rawValue);
					break;
				}

				case VALUE_DOUBLE:
				{
					value = XMPUtils.ConvertToDouble(rawValue);
					break;
				}

				case VALUE_DATE:
				{
					value = XMPUtils.ConvertToDate(rawValue);
					break;
				}

				case VALUE_CALENDAR:
				{
					XMPDateTime dt = XMPUtils.ConvertToDate(rawValue);
					value = dt.GetCalendar();
					break;
				}

				case VALUE_BASE64:
				{
					value = XMPUtils.DecodeBase64(rawValue);
					break;
				}

				case VALUE_STRING:
				default:
				{
					// leaf values return empty string instead of null
					// for the other cases the converter methods provides a "null"
					// value.
					// a default value can only occur if this method is made public.
					value = rawValue != null || propNode.GetOptions().IsCompositeProperty() ? rawValue
						 : "";
					break;
				}
			}
			return value;
		}