lfoust avatar lfoust committed 73ab0e3

Added a UnixDateTime class. I may not end up keeping it.

Comments (0)

Files changed (30)

Add a comment to this file

trunk/data/V2.0 Upgrade Checklist.xlsx

Binary file modified.

trunk/source/Stacky.Net35/Options/AnswerOptions.cs

 
 namespace Stacky
 {
+    public class OptionsBase
+    {
+        public int? Page = null;
+        public int? PageSize = null;
+        public string Filter = null;
+    }
+
+    public class Options<TSort, TMaxMin>
+        where TSort : struct
+        where TMaxMin : struct
+    {
+        public TSort? SortBy = null;
+        public SortDirection? SortDirection = null;
+        public int? Page = null;
+        public int? PageSize = null;
+        public UnixDateTime? FromDate = null;
+        public UnixDateTime? ToDate = null;
+        public TMaxMin? Min = null;
+        public TMaxMin? Max = null;
+        public string Filter = null;
+    }
+
+    public class Options<TSort> : Options<TSort, UnixDateTime>
+        where TSort : struct
+    {
+    }
+
     public class AnswerOptions
     {
         public AnswerSort SortBy = AnswerSort.Creation;

trunk/source/Stacky.Net35/Stacky.Net35.csproj

       <Link>Entities\MigrationInfo.cs</Link>
     </Compile>
     <Compile Include="..\Stacky\Entities\NetworkUser.cs">
-      <Link>NetworkUser.cs</Link>
+      <Link>Entities\NetworkUser.cs</Link>
     </Compile>
     <Compile Include="..\Stacky\Entities\Post.cs">
       <Link>Entities\Post.cs</Link>
       <Link>Entities\Revision.cs</Link>
     </Compile>
     <Compile Include="..\Stacky\Entities\ShallowUser.cs">
-      <Link>ShallowUser.cs</Link>
+      <Link>Entities\ShallowUser.cs</Link>
     </Compile>
     <Compile Include="..\Stacky\Entities\Site.cs">
       <Link>Entities\Site.cs</Link>
     <Compile Include="..\Stacky\ErrorResponse.cs">
       <Link>ErrorResponse.cs</Link>
     </Compile>
-    <Compile Include="..\Stacky\Helpers\DateHelper.cs">
-      <Link>Helpers\DateHelper.cs</Link>
-    </Compile>
     <Compile Include="..\Stacky\Helpers\EnumHelper.cs">
       <Link>Helpers\EnumHelper.cs</Link>
     </Compile>
     <Compile Include="..\Stacky\Helpers\SerializationHelper.cs">
       <Link>Helpers\SerializationHelper.cs</Link>
     </Compile>
+    <Compile Include="..\Stacky\Helpers\UnixDateTime.cs">
+      <Link>Helpers\UnixDateTime.cs</Link>
+    </Compile>
     <Compile Include="..\Stacky\Helpers\UnixDateTimeConverter.cs">
       <Link>Helpers\UnixDateTimeConverter.cs</Link>
     </Compile>

trunk/source/Stacky.Net35/StackyClient/AnswerMethods.cs

 using System.Collections.Generic;
 using System.Linq;
+using System;
 
 namespace Stacky
 {
     public partial class StackyClient
     {
-        public virtual IPagedList<Answer> GetUsersAnswers(int userId)
+        /// <summary>
+        /// See: http://api.stackexchange.com/docs/answers
+        /// </summary>
+        public IPagedList<Answer> GetAnswers()
         {
-            return GetUsersAnswers(userId.ToArray(), new AnswerOptions());
+            return GetAnswers(null);
         }
 
-        public virtual IPagedList<Answer> GetUsersAnswers(int userId, AnswerOptions options)
+        /// <summary>
+        /// See: http://api.stackexchange.com/docs/answers
+        /// </summary>
+        public IPagedList<Answer> GetAnswers(Options<AnswerSort> options)
         {
-            return GetUsersAnswers(userId.ToArray(), options);
+            return Execute<Answer>("answers", null, options);
         }
 
-        public virtual IPagedList<Answer> GetUsersAnswers(IEnumerable<int> userIds)
+        /// <summary>
+        /// See: http://api.stackexchange.com/docs/answers-by-ids
+        /// </summary>
+        public IPagedList<Answer> GetAnswers(IEnumerable<int> ids, Options<AnswerSort> options)
         {
-            return GetUsersAnswers(userIds, new AnswerOptions());
+            return Execute<Answer>("answers", new string[] { ids.Vectorize() }, options);
         }
 
-        public virtual IPagedList<Answer> GetUsersAnswers(IEnumerable<int> userIds, AnswerOptions options)
+        /// <summary>
+        /// See: http://api.stackexchange.com/docs/answers-by-ids
+        /// </summary>
+        public Answer GetAnswer(int id, Options<AnswerSort> options)
         {
-            var response = MakeRequest<Answer>("users", new string[] { userIds.Vectorize(), "answers" }, new
-            {
-                site = this.SiteUrlName,
-                page = options.Page ?? null,
-                pagesize = options.PageSize ?? null,
-                body = options.IncludeBody ? (bool?)true : null,
-                comments = options.IncludeComments ? (bool?)true : null,
-                sort = options.SortBy.ToString().ToLower(),
-                order = GetSortDirection(options.SortDirection),
-                min = options.Min ?? null,
-                max = options.Max ?? null,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null
-            });
-            return new PagedList<Answer>(response);
+            return GetAnswers(id.ToArray(), options).FirstOrDefault();
         }
 
-        public virtual IPagedList<Answer> GetQuestionAnswers(IEnumerable<int> questionIds)
+        /// <summary>
+        /// See: http://api.stackexchange.com/docs/comments-on-answers
+        /// </summary>
+        public IPagedList<Comment> GetAnswerComments(IEnumerable<int> ids, Options<AnswerSort> options)
         {
-            return GetQuestionAnswers(questionIds, new AnswerOptions());
+            return Execute<Comment>("answers", new string[] { ids.Vectorize(), "comments" }, options);
         }
 
-        public virtual IPagedList<Answer> GetQuestionAnswers(IEnumerable<int> questionIds, AnswerOptions options)
+        /// <summary>
+        /// See: http://api.stackexchange.com/docs/comments-on-answers
+        /// </summary>
+        public IPagedList<Comment> GetAnswerComments(int id, Options<AnswerSort> options)
         {
-            var response = MakeRequest<Answer>("questions", new string[] { questionIds.Vectorize(), "answers" }, new
-            {
-                site = this.SiteUrlName,
-                page = options.Page ?? null,
-                pagesize = options.PageSize ?? null,
-                body = options.IncludeBody ? (bool?)true : null,
-                comments = options.IncludeComments ? (bool?)true : null,
-                sort = options.SortBy.ToString().ToLower(),
-                order = GetSortDirection(options.SortDirection),
-                min = options.Min ?? null,
-                max = options.Max ?? null,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null
-            });
-            return new PagedList<Answer>(response);
-        }
-
-        public virtual IPagedList<Answer> GetQuestionAnswers(int questionId)
-        {
-            return GetQuestionAnswers(questionId.ToArray(), new AnswerOptions());
-        }
-
-        public virtual IPagedList<Answer> GetQuestionAnswers(int questionId, AnswerOptions options)
-        {
-            return GetQuestionAnswers(questionId.ToArray(), options);
-        }
-
-        public virtual Answer GetAnswer(int answerId)
-        {
-            return GetAnswer(answerId, new AnswerOptions());
-        }
-
-        public virtual Answer GetAnswer(int answerId, AnswerOptions options)
-        {
-            return GetAnswers(answerId.ToArray(), options).FirstOrDefault();
-        }
-
-        public virtual IPagedList<Answer> GetAnswers(IEnumerable<int> answerIds)
-        {
-            return GetAnswers(answerIds, new AnswerOptions());
-        }
-
-        public virtual IPagedList<Answer> GetAnswers(IEnumerable<int> answerIds, AnswerOptions options)
-        {
-            var response = MakeRequest<Answer>("answers", new string[] { answerIds.Vectorize() }, new
-            {
-                site = this.SiteUrlName,
-                page = options.Page ?? null,
-                pagesize = options.PageSize ?? null,
-                body = options.IncludeBody ? (bool?)true : null,
-                sort = options.SortBy.ToString().ToLower(),
-                order = GetSortDirection(options.SortDirection),
-                min = options.Min ?? null,
-                max = options.Max ?? null,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null
-            });
-            return new PagedList<Answer>(response);
+            return GetAnswerComments(id.ToArray(), options);
         }
     }
 }

trunk/source/Stacky.Net35/StackyClient/BadgeMethods.cs

                 site = this.SiteUrlName,
                 page = options.Page ?? null,
                 pagesize = options.PageSize ?? null,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
             });
             return new PagedList<User>(response);
         }

trunk/source/Stacky.Net35/StackyClient/CommentMethods.cs

                 site = this.SiteUrlName,
                 page = options.Page ?? null,
                 pagesize = options.PageSize ?? null,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
                 sort = options.SortBy.ToString().ToLower(),
                 order = GetSortDirection(options.SortDirection),
                 min = options.Min ?? null,
                 site = this.SiteUrlName,
                 page = options.Page ?? null,
                 pagesize = options.PageSize ?? null,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
                 sort = options.SortBy.ToString().ToLower(),
                 order = GetSortDirection(options.SortDirection),
             });
                 site = this.SiteUrlName,
                 page = options.Page ?? null,
                 pagesize = options.PageSize ?? null,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
                 sort = options.SortBy.ToString().ToLower(),
                 order = GetSortDirection(options.SortDirection),
                 min = options.Min ?? null,

trunk/source/Stacky.Net35/StackyClient/QuestionMethods.cs

                 body = includeBody ? (bool?)true : null,
                 comments = includeComments ? (bool?)true : null,
                 answers = includeAnswers ? (bool?)true : null,
-                fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
-                todate = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(fromDate),
+                todate = GetDateValue(toDate),
                 tagged = tags == null ? (string)null : String.Join(" ", tags),
                 sort = sort,
                 order = sortDirection,
                 site = this.SiteUrlName,
                 page = options.Page ?? null,
                 pagesize = options.PageSize ?? null,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
             });
             return new PagedList<PostEvent>(response);
         }

trunk/source/Stacky.Net35/StackyClient/RevisionMethods.cs

             return MakeRequest<Revision>("revisions", new string[] { ids.Vectorize() }, new
             {
                 site = this.SiteUrlName,
-                fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
-                todate = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null
+                fromdate = GetDateValue(fromDate),
+                todate = GetDateValue(toDate)
             }).Items;
         }
 

trunk/source/Stacky.Net35/StackyClient/StackyClientExtensions.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Stacky
+{
+    public partial class StackyClient
+    {
+        protected IPagedList<TEntity> Execute<TEntity, TSort>(string methodName, string[] urlArguments, Options<TSort, DateTime> options)
+            where TEntity : Entity, new()
+            where TSort : struct
+        {
+            var response = MakeRequest<TEntity>(methodName, urlArguments, new
+            {
+                site = this.SiteUrlName,
+                page = options.Page ?? null,
+                pagesize = options.PageSize ?? null,
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
+                sort = GetEnumValue(options.SortBy),
+                order = GetSortDirection(options.SortDirection),
+                min = GetDateValue(options.Min),
+                max = GetDateValue(options.Max),
+                filter = options.Filter
+            });
+            return new PagedList<TEntity>(response);
+        }
+
+        protected IPagedList<TEntity> Execute<TEntity, TSort, TMinMax>(string methodName, string[] urlArguments, Options<TSort, TMinMax> options)
+            where TEntity : Entity, new()
+            where TSort : struct
+            where TMinMax : struct
+        {
+            var response = MakeRequest<TEntity>(methodName, urlArguments, new
+            {
+                site = this.SiteUrlName,
+                page = options.Page ?? null,
+                pagesize = options.PageSize ?? null,
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
+                sort = GetEnumValue(options.SortBy),
+                order = GetSortDirection(options.SortDirection),
+                min = options.Min ?? null,
+                max = options.Max ?? null,
+                filter = options.Filter
+            });
+            return new PagedList<TEntity>(response);
+        }
+    }
+}

trunk/source/Stacky.Net35/StackyClient/TagMethods.cs

                 pagesize = pageSize ?? null,
                 sort = sort,
                 order = order,
-                fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
-                todate = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(fromDate),
+                todate = GetDateValue(toDate),
                 min = min ?? null,
                 max = max ?? null
             });

trunk/source/Stacky.Net35/StackyClient/UserMethods.cs

                 filter = options.Filter,
                 sort = options.SortBy.ToString().ToLower(),
                 order = GetSortDirection(options.SortDirection),
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
                 min = options.Min ?? null,
                 max = options.Max ?? null
             });
                 filter = options.Filter,
                 sort = options.SortBy.ToString().ToLower(),
                 order = GetSortDirection(options.SortDirection),
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
                 min = options.Min ?? null,
                 max = options.Max ?? null
             });
             var response = MakeRequest<UserEvent>("users", new string[] { userIds.Vectorize(), "timeline" }, new
             {
                 site = this.SiteUrlName,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
                 page = options.Page ?? null,
                 pagesize = options.PageSize ?? null
             });
             var response = MakeRequest<Reputation>("users", new string[] { userIds.Vectorize(), "reputation" }, new
             {
                 site = this.SiteUrlName,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
                 page = options.Page ?? null,
                 pagesize = options.PageSize ?? null
             });

trunk/source/Stacky.Net35/StackyClientAsync/AnswerMethods.cs

                 order = GetSortDirection(options.SortDirection),
                 min = options.Min ?? null,
                 max = options.Max ?? null,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
             }, (items) => onSuccess(new PagedList<Answer>(items)), onError);
         }
     }

trunk/source/Stacky.Net35/StackyClientAsync/BadgeMethods.cs

                 site = this.SiteUrlName,
                 page = options.Page ?? null,
                 pagesize = options.PageSize ?? null,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
             }, (items) => onSuccess(new PagedList<User>(items)), onError);
         }
 

trunk/source/Stacky.Net35/StackyClientAsync/CommentMethods.cs

                 site = this.SiteUrlName,
                 page = options.Page ?? null,
                 pagesize = options.PageSize ?? null,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
                 sort = options.SortBy.ToString().ToLower(),
                 order = GetSortDirection(options.SortDirection),
                 min = options.Min ?? null,
                 site = this.SiteUrlName,
                 page = options.Page ?? null,
                 pagesize = options.PageSize ?? null,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
                 sort = options.SortBy.ToString().ToLower(),
                 order = GetSortDirection(options.SortDirection),
             }, (items) => onSuccess(new PagedList<Comment>(items)), onError);
                 site = this.SiteUrlName,
                 page = options.Page ?? null,
                 pagesize = options.PageSize ?? null,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
                 sort = options.SortBy.ToString().ToLower(),
                 order = GetSortDirection(options.SortDirection),
                 min = options.Min ?? null,

trunk/source/Stacky.Net35/StackyClientAsync/QuestionMethods.cs

                 body = includeBody ? (bool?)true : null,
                 comments = includeComments ? (bool?)true : null,
                 answers = includeAnswers ? (bool?)true : null,
-                fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
-                todate = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(fromDate),
+                todate = GetDateValue(toDate),
                 tagged = tags == null ? (string)null : String.Join(" ", tags),
                 sort = sort,
                 order = sortDirection,
                 site = this.SiteUrlName,
                 page = options.Page ?? null,
                 pagesize = options.PageSize ?? null,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
             }, (items) => onSuccess(new PagedList<PostEvent>(items)), onError);
         }
 

trunk/source/Stacky.Net35/StackyClientAsync/RevisionMethods.cs

             MakeRequest<Revision>("revisions", new string[] { ids.Vectorize() }, new
             {
                 site = this.SiteUrlName,
-                fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
-                todate = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null
+                fromdate = GetDateValue(fromDate),
+                todate = GetDateValue(toDate),
             }, (items) => onSuccess(items.Items), onError);
         }
 

trunk/source/Stacky.Net35/StackyClientAsync/TagMethods.cs

                 pagesize = pageSize ?? null,
                 sort = sort,
                 order = order,
-                fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
-                todate = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(fromDate),
+                todate = GetDateValue(toDate),
                 min = min ?? null,
                 max = max ?? null
             }, (items) => onSuccess(new PagedList<Tag>(items)), onError);

trunk/source/Stacky.Net35/StackyClientAsync/UserMethods.cs

                 filter = options.Filter,
                 sort = options.SortBy.ToString().ToLower(),
                 order = GetSortDirection(options.SortDirection),
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
                 min = options.Min ?? null,
                 max = options.Max ?? null
             }, (items) => onSuccess(new PagedList<User>(items)), onError);
                 filter = options.Filter,
                 sort = options.SortBy.ToString().ToLower(),
                 order = GetSortDirection(options.SortDirection),
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
                 min = options.Min ?? null,
                 max = options.Max ?? null
             }, (items) => onSuccess(new PagedList<Comment>(items)), onError);
             MakeRequest<UserEvent>("users", new string[] { userIds.Vectorize(), "timeline" }, new
             {
                 site = this.SiteUrlName,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
                 page = options.Page ?? null,
                 pagesize = options.PageSize ?? null
             }, (items) => onSuccess(new PagedList<UserEvent>(items)), onError);
             MakeRequest<Reputation>("users", new string[] { userIds.Vectorize(), "reputation" }, new
             {
                 site = this.SiteUrlName,
-                fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null,
-                todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null,
+                fromdate = GetDateValue(options.FromDate),
+                todate = GetDateValue(options.ToDate),
                 page = options.Page ?? null,
                 pagesize = options.PageSize ?? null
             }, (items) => onSuccess(new PagedList<Reputation>(items)), onError);

trunk/source/Stacky.Silverlight/Stacky.Silverlight.csproj

     <Compile Include="..\Stacky\ErrorResponse.cs">
       <Link>ErrorResponse.cs</Link>
     </Compile>
-    <Compile Include="..\Stacky\Helpers\DateHelper.cs">
-      <Link>Helpers\DateHelper.cs</Link>
-    </Compile>
     <Compile Include="..\Stacky\Helpers\EnumHelper.cs">
       <Link>Helpers\EnumHelper.cs</Link>
     </Compile>
     <Compile Include="..\Stacky\Helpers\SerializationHelper.cs">
       <Link>Helpers\SerializationHelper.cs</Link>
     </Compile>
+    <Compile Include="..\Stacky\Helpers\UnixDateTime.cs">
+      <Link>Helpers\UnixDateTime.cs</Link>
+    </Compile>
     <Compile Include="..\Stacky\Helpers\UnixDateTimeConverter.cs">
       <Link>Helpers\UnixDateTimeConverter.cs</Link>
     </Compile>

trunk/source/Stacky.WindowsPhone/Stacky.WindowsPhone.csproj

     <Compile Include="..\Stacky\ErrorResponse.cs">
       <Link>ErrorResponse.cs</Link>
     </Compile>
-    <Compile Include="..\Stacky\Helpers\DateHelper.cs">
-      <Link>Helpers\DateHelper.cs</Link>
-    </Compile>
     <Compile Include="..\Stacky\Helpers\EnumHelper.cs">
       <Link>Helpers\EnumHelper.cs</Link>
     </Compile>
     <Compile Include="..\Stacky\Helpers\SerializationHelper.cs">
       <Link>Helpers\SerializationHelper.cs</Link>
     </Compile>
+    <Compile Include="..\Stacky\Helpers\UnixDateTime.cs">
+      <Link>Helpers\UnixDateTime.cs</Link>
+    </Compile>
     <Compile Include="..\Stacky\Helpers\UnixDateTimeConverter.cs">
       <Link>Helpers\UnixDateTimeConverter.cs</Link>
     </Compile>

trunk/source/Stacky/Helpers/DateHelper.cs

-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Stacky
-{
-    /// <summary>
-    /// Unix time helper methods.
-    /// </summary>
-    public static class DateHelper
-    {
-        static DateTime _unixEpoch = new DateTime(1970, 1, 1);
-
-        /// <summary>
-        /// Converts unix time to <see cref="System.DateTime"/>.
-        /// </summary>
-        /// <param name="self">The <see cref="System.DateTime"/>.</param>
-        /// <returns></returns>
-        public static DateTime FromUnixTime(this Int64 self)
-        {
-            return _unixEpoch.AddSeconds(self);
-        }
-
-        /// <summary>
-        /// Converts <see cref="System.DateTime"/> to unix time.
-        /// </summary>
-        /// <param name="self">The unix time.</param>
-        /// <returns></returns>
-        public static Int64 ToUnixTime(this DateTime self)
-        {
-            var delta = self - _unixEpoch;
-
-            if (delta.TotalSeconds < 0) throw new ArgumentOutOfRangeException("self", "Unix epoch starts January 1st, 1970");
-
-            return (long)delta.TotalSeconds;
-        }
-    }
-}

trunk/source/Stacky/Helpers/UnixDateTime.cs

+namespace Stacky
+{
+    using System;
+
+    public struct UnixDateTime : 
+        IEquatable<UnixDateTime>, 
+        IEquatable<long>, 
+        IEquatable<DateTime>,
+        IComparable<UnixDateTime>,
+        IComparable<long>,
+        IComparable<DateTime>
+    {
+        private DateTime value;
+        public static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1);
+
+        #region Constructor
+
+        public UnixDateTime(DateTime value)
+        {
+            this.value = value;
+        }
+
+        public UnixDateTime(long value)
+        {
+            this.value = UnixDateTime.DateFromUnixTime(value);
+        }
+
+        #endregion
+
+        #region Properties
+
+        public long UnixValue
+        {
+            get { return UnixDateTime.UnixTimeFromDate(value); }
+        }
+
+        public DateTime DateValue
+        {
+            get { return value; }
+        }
+
+        #endregion
+
+        #region Conversion
+
+        public static DateTime DateFromUnixTime(long value)
+        {
+            return UnixEpoch.AddSeconds(value);
+        }
+
+        public static Int64 UnixTimeFromDate(DateTime value)
+        {
+            var delta = value - UnixEpoch;
+
+            if (delta.TotalSeconds < 0) throw new ArgumentOutOfRangeException("self", "Unix epoch starts January 1st, 1970");
+
+            return (long)delta.TotalSeconds;
+        }
+
+        #endregion
+
+        #region ToString
+
+        public override string ToString()
+        {
+            return UnixValue.ToString();
+        }
+
+        public override int GetHashCode()
+        {
+            return UnixValue.GetHashCode();
+        }
+
+        #endregion
+
+        #region Equals
+
+        public bool Equals(DateTime other)
+        {
+            if (Object.Equals(other, null))
+                return false;
+            return DateValue == other;
+        }
+
+        public bool Equals(long other)
+        {
+            return UnixValue == other;
+        }
+
+        public bool Equals(UnixDateTime other)
+        {
+            if (Object.Equals(other, null))
+            {
+                return false;
+            }
+            return other.DateValue == DateValue;
+        }
+
+        public override bool Equals(object obj)
+        {
+            if (obj == null || GetType() != obj.GetType())
+            {
+                return false;
+            }
+            return Equals((UnixDateTime)obj);
+        }
+
+        #endregion
+
+        #region Operators
+
+        public static implicit operator DateTime(UnixDateTime value)
+        {
+            return value.DateValue;
+        }
+
+        public static implicit operator long(UnixDateTime value)
+        {
+            return value.UnixValue;
+        }
+
+        public static implicit operator UnixDateTime(long value)
+        {
+            return new UnixDateTime(value);
+        }
+
+        public static implicit operator UnixDateTime(DateTime value)
+        {
+            return new UnixDateTime(value);
+        }
+
+        public static bool operator ==(UnixDateTime d1, UnixDateTime d2)
+        {
+            if (Object.Equals(d1, null))
+            {
+                return false;
+            }
+            return d1.Equals(d2);
+        }
+
+        public static bool operator !=(UnixDateTime d1, UnixDateTime d2)
+        {
+            if (Object.Equals(d1, null))
+            {
+                return false;
+            }
+            return !d1.Equals(d2);
+        }
+
+        public static bool operator <(UnixDateTime d1, UnixDateTime d2)
+        {
+            if (Object.Equals(d1, null) || Object.Equals(d2, null))
+            {
+                return false;
+            }
+            return d1.DateValue < d2.DateValue;
+        }
+
+        public static bool operator <=(UnixDateTime d1, UnixDateTime d2)
+        {
+            if (Object.Equals(d1, null) || Object.Equals(d2, null))
+            {
+                return false;
+            }
+            return d1.DateValue <= d2.DateValue;
+        }
+
+        public static bool operator >(UnixDateTime d1, UnixDateTime d2)
+        {
+            if (Object.Equals(d1, null) || Object.Equals(d2, null))
+            {
+                return false;
+            }
+            return d1.DateValue > d2.DateValue;
+        }
+
+        public static bool operator >=(UnixDateTime d1, UnixDateTime d2)
+        {
+            if (Object.Equals(d1, null) || Object.Equals(d2, null))
+            {
+                return false;
+            }
+            return d1.DateValue >= d2.DateValue;
+        }
+
+        #endregion
+
+        #region CompareTo
+
+        public int CompareTo(UnixDateTime other)
+        {
+            if (Object.Equals(other, null))
+            {
+                throw new ArgumentNullException("other");
+            }
+            return DateValue.CompareTo(other.DateValue);
+        }
+
+        public int CompareTo(long other)
+        {
+            if (Object.Equals(other, null))
+            {
+                throw new ArgumentNullException("other");
+            }
+            return UnixValue.CompareTo(other);
+        }
+
+        public int CompareTo(DateTime other)
+        {
+            if (Object.Equals(other, null))
+            {
+                throw new ArgumentNullException("other");
+            }
+            return DateValue.CompareTo(other);
+        }
+
+        #endregion
+    }
+}

trunk/source/Stacky/Helpers/UnixDateTimeConverter.cs

             if (value is DateTime)
             {
                 DateTime dateTime = (DateTime)value;
-                val = dateTime.ToUnixTime();
+                val = UnixDateTime.UnixTimeFromDate(dateTime);
             }
             else
             {
                 throw new Exception("Wrong Token Type");
 
             long ticks = (long)reader.Value;
-            return ticks.FromUnixTime();
+            return UnixDateTime.DateFromUnixTime(ticks);
         }
     }
 }

trunk/source/Stacky/Stacky.csproj

     <Compile Include="Enums\UserType.cs" />
     <Compile Include="Enums\VoteType.cs" />
     <Compile Include="ErrorResponse.cs" />
-    <Compile Include="Helpers\DateHelper.cs" />
     <Compile Include="Helpers\EnumHelper.cs" />
     <Compile Include="Helpers\Execute.cs" />
     <Compile Include="Helpers\Paging\PageEnumerator.cs" />
     <Compile Include="Helpers\Paging\StackyEnumerator.cs" />
     <Compile Include="Helpers\Require.cs" />
     <Compile Include="Helpers\SerializationHelper.cs" />
+    <Compile Include="Helpers\UnixDateTime.cs" />
     <Compile Include="Helpers\UnixDateTimeConverter.cs" />
     <Compile Include="Helpers\UrlHelper.cs" />
     <Compile Include="HttpResponse.cs" />

trunk/source/Stacky/StackyClient/StackyClient.cs

             return new PagedList<TEntity>(response);
         }
 
-		protected void ValidateVectorizedParameters(IEnumerable<int> items)
+        protected void ValidateVectorizedParameters(IEnumerable<int> items)
 		{
 			if (items.Count() > 100)
 				throw new ArgumentOutOfRangeException("Paramaterized arguments cannot have more than 100 items in them");

trunk/source/Stacky/StackyClientBase.cs

         protected long? GetDateValue(DateTime? date)
         {
             if (date.HasValue)
-                return (long?)date.Value.ToUnixTime();
+                return UnixDateTime.UnixTimeFromDate(date.Value);
             return null;
         }
     }

trunk/source/Tests/Stacky.Net35.IntegrationTests/AnswerTests.cs

     [TestClass]
     public class AnswerTests : IntegrationTest
     {
-        [TestMethod]
-        public void Answer_GetQuestionAnswers()
-        {
-            var answers = Client.GetQuestionAnswers(31415);
-            Assert.IsNotNull(answers);
-        }
+        //[TestMethod]
+        //public void Answer_GetQuestionAnswers()
+        //{
+        //    var answers = Client.GetQuestionAnswers(31415);
+        //    Assert.IsNotNull(answers);
+        //}
 
-        [TestMethod]
-        public void Answer_GetQuestionAnswers_ContainsPagingInformation()
-        {
-            var answers = Client.GetQuestionAnswers(31415);
-            Assert.IsNotNull(answers);
-            Assert.IsTrue(answers.PageSize > 0);
-            Assert.IsTrue(answers.CurrentPage > 0);
-            Assert.IsTrue(answers.TotalItems > 0);
-        }
+        //[TestMethod]
+        //public void Answer_GetQuestionAnswers_ContainsPagingInformation()
+        //{
+        //    var answers = Client.GetQuestionAnswers(31415);
+        //    Assert.IsNotNull(answers);
+        //    Assert.IsTrue(answers.PageSize > 0);
+        //    Assert.IsTrue(answers.CurrentPage > 0);
+        //    Assert.IsTrue(answers.TotalItems > 0);
+        //}
 
-        [TestMethod]
-        public void Answer_GetUsersAnswers_ContainsPagingInformation()
-        {
-            var answers = Client.GetUsersAnswers(1464);
-            Assert.IsNotNull(answers);
-            Assert.IsTrue(answers.PageSize > 0);
-            Assert.IsTrue(answers.CurrentPage > 0);
-            Assert.IsTrue(answers.TotalItems > 0);
-        }
+        //[TestMethod]
+        //public void Answer_GetUsersAnswers_ContainsPagingInformation()
+        //{
+        //    var answers = Client.GetUsersAnswers(1464);
+        //    Assert.IsNotNull(answers);
+        //    Assert.IsTrue(answers.PageSize > 0);
+        //    Assert.IsTrue(answers.CurrentPage > 0);
+        //    Assert.IsTrue(answers.TotalItems > 0);
+        //}
 
-        [TestMethod]
-        public void ContainsOwnerAsObject()
-        {
-            var answer = Client.GetUsersAnswers(1464).FirstOrDefault();
+        //[TestMethod]
+        //public void ContainsOwnerAsObject()
+        //{
+        //    var answer = Client.GetUsersAnswers(1464).FirstOrDefault();
 
-            Assert.IsNotNull(answer);
-            Assert.IsNotNull(answer.Owner);
-            Assert.IsNotNull(answer.Owner.DisplayName);
-        }
+        //    Assert.IsNotNull(answer);
+        //    Assert.IsNotNull(answer.Owner);
+        //    Assert.IsNotNull(answer.Owner.DisplayName);
+        //}
 
-        [TestMethod]
-        public void Answer_GetAnswer()
-        {
-            var answer = Client.GetAnswer(11738);
-            Assert.IsNotNull(answer);
-        }
+        //[TestMethod]
+        //public void Answer_GetAnswer()
+        //{
+        //    var answer = Client.GetAnswer(11738);
+        //    Assert.IsNotNull(answer);
+        //}
 
-        [TestMethod]
-        public void Answer_GetAnswers()
-        {
-            var answers = Client.GetAnswers(new int[] { 11738, 122784 });
-            Assert.IsNotNull(answers);
-        }
+        //[TestMethod]
+        //public void Answer_GetAnswers()
+        //{
+        //    var answers = Client.GetAnswers(new int[] { 11738, 122784 });
+        //    Assert.IsNotNull(answers);
+        //}
     }
 }

trunk/source/Tests/Stacky.Net35.IntegrationTests/UserTests.cs

             Assert.IsTrue(mentions.TotalItems > 0);
         }
 
-        [TestMethod]
-        public void User_GetQuestionAnswers()
-        {
-            var answers = Client.GetQuestionAnswers(31415);
-            Assert.IsNotNull(answers);
-        }
+        //[TestMethod]
+        //public void User_GetQuestionAnswers()
+        //{
+        //    var answers = Client.GetQuestionAnswers(31415);
+        //    Assert.IsNotNull(answers);
+        //}
 
-        [TestMethod]
-        public void User_GetQuestionAnswers_ContainsPagingInformation()
-        {
-            var answers = Client.GetQuestionAnswers(31415);
-            Assert.IsNotNull(answers);
-            Assert.IsTrue(answers.PageSize > 0);
-            Assert.IsTrue(answers.CurrentPage > 0);
-            Assert.IsTrue(answers.TotalItems > 0);
-        }
+        //[TestMethod]
+        //public void User_GetQuestionAnswers_ContainsPagingInformation()
+        //{
+        //    var answers = Client.GetQuestionAnswers(31415);
+        //    Assert.IsNotNull(answers);
+        //    Assert.IsTrue(answers.PageSize > 0);
+        //    Assert.IsTrue(answers.CurrentPage > 0);
+        //    Assert.IsTrue(answers.TotalItems > 0);
+        //}
 
         [TestMethod]
         public void User_GetUserTimeline()

trunk/source/Tests/Stacky.UnitTests/DateTests.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Stacky.UnitTests
+{
+    [TestClass]
+    public class DateTests
+    {
+        [TestMethod]
+        public void ImplicitUnixDateToLong()
+        {
+            DateTime date = DateTime.Now;
+            UnixDateTime unixDate = new UnixDateTime(date);
+
+            long actual = unixDate;
+            long expected = UnixDateTime.UnixTimeFromDate(date);
+            Assert.AreEqual(expected, actual);
+        }
+
+        [TestMethod]
+        public void ImplicitLongToUnixDate()
+        {
+            long date = UnixDateTime.UnixTimeFromDate(DateTime.Now);
+            UnixDateTime unixDate = date;
+
+            Assert.AreEqual(date, unixDate.UnixValue);
+        }
+
+        [TestMethod]
+        public void ImplicitDateTimeToUnixDate()
+        {
+            DateTime date = DateTime.Now;
+            UnixDateTime unixDate = date;
+
+            Assert.AreEqual(date, unixDate.DateValue);
+        }
+
+        [TestMethod]
+        public void ImplicitUnixDateToDateTime()
+        {
+            DateTime date = DateTime.Now;
+            UnixDateTime unixDate = new UnixDateTime(date);
+
+            DateTime actual = unixDate;
+            Assert.AreEqual(date, actual);
+        }
+
+        [TestMethod]
+        public void ToString_IsUnixDate()
+        {
+            long date = UnixDateTime.UnixTimeFromDate(DateTime.Now);
+            UnixDateTime unixDate = new UnixDateTime(date);
+
+            Assert.AreEqual(date.ToString(), unixDate.ToString());
+        }
+
+        [TestMethod]
+        public void Uninitialized_DoesntThrowException()
+        {
+            UnixDateTime value = new UnixDateTime();
+            string s = value.ToString();
+            long unix = value;
+            DateTime date = value;
+
+            value = 1;
+            value = DateTime.Now;
+        }
+    }
+}

trunk/source/Tests/Stacky.UnitTests/Stacky.UnitTests.csproj

     </CodeAnalysisDependentAssemblyPaths>
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="DateTests.cs" />
     <Compile Include="EnumTests.cs" />
     <Compile Include="PagerTests.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.