Beispiel #1
0
        /// <summary>
        /// Parse a metadata-formatted date/time string into a DateTimeOffset. Return false on failure
        /// </summary>
        public static bool TryParseMetadataDateTaken(string dateTimeAsString, TimeZoneInfo imageSetTimeZone, out DateTimeOffset dateTimeOffset)
        {
            if (DateTime.TryParseExact(dateTimeAsString, Constant.Time.DateTimeMetadataFormats, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTime) == false)
            {
                dateTimeOffset = DateTimeOffset.MinValue;
                return(false);
            }

            dateTimeOffset = DateTimeHandler.CreateDateTimeOffset(dateTime, imageSetTimeZone);
            return(true);
        }
        private static bool TryParseDateTaken(string dateTimeAsString, TimeZoneInfo imageSetTimeZone, out DateTimeOffset dateTimeOffset)
        {
            // use current culture as BitmapMetadata.DateTaken is not invariant
            if (DateTime.TryParse(dateTimeAsString, CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime dateTime) == false)
            {
                dateTimeOffset = DateTimeOffset.MinValue;
                return(false);
            }

            dateTimeOffset = DateTimeHandler.CreateDateTimeOffset(dateTime, imageSetTimeZone);
            return(true);
        }
        /// <summary>
        /// Parse a metadata-formatted date/time string exactly into a DateTimeOffset.
        /// Note that this only accepts 'standard' date/time forms as described in Constant.Time.DateTimeMetadataFormat
        /// Return false on failure
        /// </summary>
        public static bool TryParseMetadataDateTaken(string dateTimeAsString, TimeZoneInfo imageSetTimeZone, out DateTimeOffset dateTimeOffset)
        {
            if (false == DateTime.TryParseExact(dateTimeAsString, Constant.Time.DateTimeMetadataFormats, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTime))
            {
                // Commented out section skips the general form, which can accept weird incomplete values that are not really useful e.g. 3.5
                //if (false == DateTime.TryParse(dateTimeAsString, out dateTime))
                //{
                dateTimeOffset = DateTimeOffset.MinValue;
                return(false);
                //}
                //return false;
            }

            dateTimeOffset = DateTimeHandler.CreateDateTimeOffset(dateTime, imageSetTimeZone);
            return(true);
        }