ParseDateWithGranularity() публичный статический Метод

Parses a date which may contain only a vald year component.
public static ParseDateWithGranularity ( string date ) : System.DateTime
date string The date, as a string, to be parsed.
Результат System.DateTime
Пример #1
0
        void IFlickrParsable.Load(System.Xml.XmlReader reader)
        {
            reader.Read();

            while (reader.LocalName != "photos")
            {
                switch (reader.LocalName)
                {
                case "firstdatetaken":
                    FirstTakenDate = UtilityMethods.ParseDateWithGranularity(reader.ReadElementContentAsString());
                    break;

                case "firstdate":
                    FirstDate = UtilityMethods.UnixTimestampToDate(reader.ReadElementContentAsString());
                    break;

                case "count":
                    PhotoCount = reader.ReadElementContentAsInt();
                    break;

                case "views":
                    Views = reader.ReadElementContentAsInt();
                    break;

                default:
                    UtilityMethods.CheckParsingException(reader);
                    reader.Skip();
                    break;
                }
            }

            reader.Read();
        }
Пример #2
0
        private void ParseDates(System.Xml.XmlReader reader)
        {
            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                    case "posted":
                        DatePosted = UtilityMethods.UnixTimestampToDate(reader.Value);
                        break;
                    case "taken":
                        DateTaken = UtilityMethods.ParseDateWithGranularity(reader.Value);
                        break;
                    case "takengranularity":
                        DateTakenGranularity = (DateGranularity)int.Parse(reader.Value, System.Globalization.NumberFormatInfo.InvariantInfo);
                        break;
                    case "lastupdate":
                        DateLastUpdated = UtilityMethods.UnixTimestampToDate(reader.Value);
                        break;
                    default:
                        UtilityMethods.CheckParsingException(reader);
                        break;
                }
            }

            reader.Read();
        }
Пример #3
0
        /// <summary>
        /// Protected method that does the actual initialization of the Photo instance. Should be called by subclasses of the Photo class.
        /// </summary>
        /// <param name="reader">The reader containing the XML to be parsed.</param>
        /// <param name="allowExtraAtrributes">Wheither to allow unknown extra attributes. In debug builds will throw an exception if this parameter is false and an unknown attribute is found.</param>
        protected void Load(XmlReader reader, bool allowExtraAtrributes)
        {
            if (reader.LocalName != "photo")
            {
                UtilityMethods.CheckParsingException(reader);
            }

            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "id":
                    PhotoId = reader.Value;
                    if (String.IsNullOrEmpty(reader.Value))
                    {
                        reader.Skip();
                        return;
                    }
                    break;

                case "owner":
                    UserId = reader.Value;
                    break;

                case "secret":
                    Secret = reader.Value;
                    break;

                case "server":
                    Server = reader.Value;
                    break;

                case "farm":
                    Farm = reader.Value;
                    break;

                case "title":
                    Title = reader.Value;
                    break;

                case "ispublic":
                    IsPublic = reader.Value == "1";
                    break;

                case "isfamily":
                    IsFamily = reader.Value == "1";
                    break;

                case "isfriend":
                    IsFriend = reader.Value == "1";
                    break;

                case "tags":
                    foreach (string tag in reader.Value.Split(' '))
                    {
                        Tags.Add(tag);
                    }
                    break;

                case "datetaken":
                    // For example : 2007-11-04 08:55:18
                    DateTaken = UtilityMethods.ParseDateWithGranularity(reader.Value);
                    break;

                case "datetakengranularity":
                    break;

                case "dateupload":
                    DateUploaded = UtilityMethods.UnixTimestampToDate(reader.Value);
                    break;

                case "license":
                    License = (LicenseType)int.Parse(reader.Value, System.Globalization.CultureInfo.InvariantCulture);
                    break;

                case "ownername":
                    OwnerName = reader.Value;
                    break;

                case "lastupdate":
                    LastUpdated = UtilityMethods.UnixTimestampToDate(reader.Value);
                    break;

                case "originalformat":
                    OriginalFormat = reader.Value;
                    break;

                case "originalsecret":
                    OriginalSecret = reader.Value;
                    break;

                case "place_id":
                    PlaceId = reader.Value;
                    break;

                case "woeid":
                    WoeId = reader.Value;
                    break;

                case "accuracy":
                    Accuracy = (GeoAccuracy)reader.ReadContentAsInt();
                    break;

                case "latitude":
                    Latitude = reader.ReadContentAsDouble();
                    break;

                case "longitude":
                    Longitude = reader.ReadContentAsDouble();
                    break;

                case "machine_tags":
                    MachineTags = reader.Value;
                    break;

                case "o_width":
                    OriginalWidth = int.Parse(reader.Value, System.Globalization.CultureInfo.InvariantCulture);
                    break;

                case "o_height":
                    OriginalHeight = int.Parse(reader.Value, System.Globalization.CultureInfo.InvariantCulture);
                    break;

                case "views":
                    Views = int.Parse(reader.Value, System.Globalization.CultureInfo.InvariantCulture);
                    break;

                case "media":
                    Media = reader.Value;
                    break;

                case "media_status":
                    MediaStatus = reader.Value;
                    break;

                case "iconserver":
                    IconServer = reader.Value;
                    break;

                case "iconfarm":
                    IconFarm = reader.Value;
                    break;

                case "username":
                    OwnerName = reader.Value;
                    break;

                case "isprimary":
                case "is_primary":
                    break;

                case "pathalias":
                    PathAlias = reader.Value;
                    break;

                case "url_sq":
                    urlSquare = reader.Value;
                    break;

                case "width_sq":
                    SquareThumbnailWidth = reader.ReadContentAsInt();
                    break;

                case "height_sq":
                    SquareThumbnailHeight = reader.ReadContentAsInt();
                    break;

                case "url_t":
                    urlThumbnail = reader.Value;
                    break;

                case "width_t":
                    ThumbnailWidth = reader.ReadContentAsInt();
                    break;

                case "height_t":
                    ThumbnailHeight = reader.ReadContentAsInt();
                    break;

                case "url_s":
                    urlSmall = reader.Value;
                    break;

                case "width_s":
                    SmallWidth = reader.ReadContentAsInt();
                    break;

                case "height_s":
                    SmallHeight = reader.ReadContentAsInt();
                    break;

                case "url_m":
                    urlMedium = reader.Value;
                    break;

                case "width_m":
                    MediumWidth = reader.ReadContentAsInt();
                    break;

                case "height_m":
                    MediumHeight = reader.ReadContentAsInt();
                    break;

                case "url_l":
                    urlLarge = reader.Value;
                    break;

                case "width_l":
                    LargeWidth = reader.ReadContentAsInt();
                    break;

                case "height_l":
                    LargeHeight = reader.ReadContentAsInt();
                    break;

                case "url_z":
                    urlMedium640 = reader.Value;
                    break;

                case "width_z":
                    Medium640Width = reader.ReadContentAsInt();
                    break;

                case "height_z":
                    Medium640Height = reader.ReadContentAsInt();
                    break;

                case "url_o":
                    urlOriginal = reader.Value;
                    break;

                case "width_o":
                    OriginalWidth = reader.ReadContentAsInt();
                    break;

                case "height_o":
                    OriginalHeight = reader.ReadContentAsInt();
                    break;

                case "dateadded":
                    DateAddedToGroup = UtilityMethods.UnixTimestampToDate(reader.Value);
                    break;

                case "date_faved":
                    DateFavorited = UtilityMethods.UnixTimestampToDate(reader.Value);
                    break;

                case "has_comment":     // Gallery photos return this, but we ignore it and set GalleryPhoto.Comment instead.
                    break;

                case "can_comment":
                    CanComment = reader.Value == "1";
                    break;

                case "can_addmeta":
                    CanAddMeta = reader.Value == "1";
                    break;

                case "can_blog":
                    CanBlog = reader.Value == "1";
                    break;

                case "can_print":
                    CanPrint = reader.Value == "1";
                    break;

                case "can_download":
                    CanDownload = reader.Value == "1";
                    break;

                case "can_share":
                    CanShare = reader.Value == "1";
                    break;

                case "geo_is_family":
                    if (GeoPermissions == null)
                    {
                        GeoPermissions         = new GeoPermissions();
                        GeoPermissions.PhotoId = PhotoId;
                    }
                    GeoPermissions.IsFamily = reader.Value == "1";
                    break;

                case "geo_is_friend":
                    if (GeoPermissions == null)
                    {
                        GeoPermissions         = new GeoPermissions();
                        GeoPermissions.PhotoId = PhotoId;
                    }
                    GeoPermissions.IsFriend = reader.Value == "1";
                    break;

                case "geo_is_public":
                    if (GeoPermissions == null)
                    {
                        GeoPermissions         = new GeoPermissions();
                        GeoPermissions.PhotoId = PhotoId;
                    }
                    GeoPermissions.IsPublic = reader.Value == "1";
                    break;

                case "geo_is_contact":
                    if (GeoPermissions == null)
                    {
                        GeoPermissions         = new GeoPermissions();
                        GeoPermissions.PhotoId = PhotoId;
                    }
                    GeoPermissions.IsContact = reader.Value == "1";
                    break;

                default:
                    if (!allowExtraAtrributes)
                    {
                        UtilityMethods.CheckParsingException(reader);
                    }
                    break;
                }
            }

            reader.Read();

            if (reader.LocalName == "description")
            {
                Description = reader.ReadElementContentAsString();
            }
        }