Ejemplo n.º 1
0
        public ITentRequestDate FromPost(ITentRequestPost post, TentFeedRequestSort sortBy)
        {
            Ensure.Argument.IsNotNull(post, nameof(post));
            Ensure.Argument.IsNotNull(post.Post, nameof(post.Post));

            // Create the resulting Request Date object.
            var result = new TentRequestDate(this.uriHelpers)
            {
                Version = post.Post.Version.Id
            };

            // Pick the correct date on the specified post.
            switch (sortBy)
            {
                case TentFeedRequestSort.VersionPublishedAt:
                    result.Date = post.Post.Version.PublishedAt.GetValueOrDefault();
                    break;
                case TentFeedRequestSort.VersionReceivedAt:
                    result.Date = post.Post.Version.ReceivedAt.GetValueOrDefault();
                    break;
                case TentFeedRequestSort.PublishedAt:
                    result.Date = post.Post.PublishedAt.GetValueOrDefault();
                    break;
                default:
                    result.Date = post.Post.ReceivedAt.GetValueOrDefault();
                    break;
            }

            return result;
        }
Ejemplo n.º 2
0
        public ITentRequestDate FromString(string date)
        {
            Ensure.Argument.IsNotNullOrWhiteSpace(date, nameof(date));
            var requestDateParts = date.Split('+');

            // Make sure we have something in the array.
            if (!requestDateParts.Any())
                throw new ArgumentOutOfRangeException(nameof(date), "The provided Tent date isn't valid.");

            // Try to extract the date.
            var dateValue = requestDateParts[0].TryParseLong();
            if (!dateValue.HasValue)
                throw new ArgumentOutOfRangeException(nameof(date), "The provided Tent date isn't valid.");

            // Create the resulting Request Date object.
            var result = new TentRequestDate(this.uriHelpers)
            {
                Date = dateValue.Value.FromUnixTime()
            };

            // Extract the version, if any.
            if (requestDateParts.Length > 1)
                result.Version = this.uriHelpers.UrlDecode(requestDateParts[1]);

            return result;
        }