public RedirectItem() { Row = new RedirectItemRow(); _created = EssentialsDateTime.Now; _updated = EssentialsDateTime.Now; Row.UniqueId = Guid.NewGuid().ToString(); }
/// <summary> /// Initializes a new instance from the specified <paramref name="date"/>. /// </summary> /// <param name="date">An instance of <see cref="EssentialsDateTime"/> representing the full date.</param> public EssentialsPartialDate(EssentialsDateTime date) { Year = date == null ? 0 : date.Year; Month = date == null ? 0 : date.Month; Day = date == null ? 0 : date.Day; DateTime = new DateTime(Year == 0 ? 1 : Year, Month == 0 ? 1 : Month, Day == 0 ? 1 : Day); }
/// <summary> /// Initializes an instance with the specified <paramref name="identifier"/>, <paramref name="limit"/>, /// <paramref name="until"/> and collection of <paramref name="fields"/>. /// </summary> /// <param name="identifier">The identifier (ID) of the page or user.</param> /// <param name="limit">The maximum amount of items to be returned per page.</param> /// <param name="until">The timestamp that points to the end of the range of time-based data.</param> /// <param name="fields">A collection of the fields that should be returned by the API.</param> public FacebookGetPostsOptions(string identifier, int limit, EssentialsDateTime until, FacebookFieldsCollection fields) : this() { Identifier = identifier; Limit = limit; Until = until; Fields = fields ?? new FacebookFieldsCollection(); }
/// <summary> /// Reads the JSON representation of the object. /// </summary> /// <param name="reader">The <see cref="JsonReader"/> to read from.</param> /// <param name="objectType">Type of the object.</param> /// <param name="existingValue">The existing value of object being read.</param> /// <param name="serializer">The calling serializer.</param> /// <returns>The object value.</returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { double timestamp; switch (reader.TokenType) { case JsonToken.Null: return objectType == typeof(DateTime) ? (object) default(DateTime) : null; case JsonToken.Integer: timestamp = (long) reader.Value; break; case JsonToken.Float: timestamp = (double) reader.Value; break; case JsonToken.String: if (!Double.TryParse(reader.Value + "", out timestamp)) throw new JsonSerializationException("String value doesn't match a Unix timestamp: " + reader.Value); break; default: throw new JsonSerializationException("Unexpected token type: " + reader.TokenType); } if (objectType == typeof(EssentialsDateTime)) return EssentialsDateTime.FromUnixTimestamp(timestamp); if (objectType == typeof(DateTime)) return TimeUtils.GetDateTimeFromUnixTime(timestamp); throw new JsonSerializationException("Object type " + objectType + " is not supported"); }
/// <summary> /// Initializes a new instance based on the specified <paramref name="identifier"/>, <paramref name="limit"/> /// and <paramref name="until"/>. /// </summary> /// <param name="identifier">The identifier (ID) of the page or user.</param> /// <param name="limit">The maximum amount of items to be returned per page.</param> /// <param name="until">The timestamp that points to the end of the range of time-based data.</param> public FacebookGetFeedOptions(string identifier, int limit, EssentialsDateTime until) { Identifier = identifier; Limit = limit; Until = until; Fields = new FacebookFieldsCollection(); }
/// <summary> /// Initializes a new instance based on the specified <paramref name="obj"/>. /// </summary> /// <param name="obj">The instance of <see cref="JObject"/> representing the event.</param> protected FacebookEvent(JObject obj) : base(obj) { Id = obj.GetString("id"); AttendingCount = obj.GetInt32("attending_count"); CanGuestsInvite = obj.GetBoolean("can_guests_invite"); Category = obj.GetEnum("category", FacebookEventCategory.Unspecified); Cover = obj.GetObject("cover", FacebookCoverPhoto.Parse); DeclinedCount = obj.GetInt32("declined_count"); Description = obj.GetString("description"); EndTime = obj.GetString("end_time", EssentialsDateTime.Parse); GuestListEnabled = obj.GetBoolean("guest_list_enabled"); InterestedCount = obj.GetInt32("interested_count"); IsCanceled = obj.GetBoolean("is_canceled"); IsPageOwned = obj.GetBoolean("is_page_owned"); IsViewerAdmin = obj.GetBoolean("is_viewer_admin"); MaybeCount = obj.GetInt32("maybe_count"); Name = obj.GetString("name"); NoreplyCount = obj.GetInt32("noreply_count"); Owner = obj.GetObject("owner", FacebookEventOwner.Parse); // parent_group"); Place = obj.GetObject("place", FacebookPlace.Parse); StartTime = obj.GetString("start_time", EssentialsDateTime.Parse); TicketUri = obj.GetString("ticket_uri"); Timezone = obj.GetString("timezone"); Type = obj.GetEnum("type", FacebookEventType.Unspecified); UpdatedTime = obj.GetString("updated_time", EssentialsDateTime.Parse); }
private FacebookDebugTokenData(JObject obj) : base(obj) { // If an access token doesn't have an expire date, it may be specified as "0". In other scenarios, the // property is not present at all. In either case, we should set the "ExpiresAt" property to "NULL". EssentialsDateTime expiresAt = null; if (obj.HasValue("expires_at")) { int value = obj.GetInt32("expires_at"); if (value > 0) { expiresAt = EssentialsDateTime.FromUnixTimestamp(value); } } // Parse the array of scopes FacebookScope[] scopes = ( from name in obj.GetArray("scopes", x => x.ToString()) ?? new string[0] select FacebookScope.GetScope(name) ?? new FacebookScope(name) ).ToArray(); // Populate the properties AppId = obj.GetInt64("app_id"); Application = obj.GetString("application"); ExpiresAt = expiresAt; IsValid = obj.GetBoolean("is_valid"); IssuedAt = obj.HasValue("issued_at") ? obj.GetInt64("issued_at", EssentialsDateTime.FromUnixTimestamp) : null; UserId = obj.GetString("user_id"); Scopes = scopes; }
public void GetWeekNumber() { EssentialsDateTime dec27 = new EssentialsDateTime(2021, 12, 27, 0, 0, 0); EssentialsDateTime dec28 = new EssentialsDateTime(2021, 12, 28, 0, 0, 0); EssentialsDateTime dec29 = new EssentialsDateTime(2021, 12, 29, 0, 0, 0); EssentialsDateTime dec30 = new EssentialsDateTime(2021, 12, 30, 0, 0, 0); EssentialsDateTime dec31 = new EssentialsDateTime(2021, 12, 31, 0, 0, 0); EssentialsDateTime jan01 = new EssentialsDateTime(2022, 1, 1, 0, 0, 0); EssentialsDateTime jan02 = new EssentialsDateTime(2022, 1, 2, 0, 0, 0); EssentialsDateTime jan03 = new EssentialsDateTime(2022, 1, 3, 0, 0, 0); EssentialsDateTime jan04 = new EssentialsDateTime(2022, 1, 4, 0, 0, 0); EssentialsDateTime jan05 = new EssentialsDateTime(2022, 1, 5, 0, 0, 0); EssentialsDateTime jan06 = new EssentialsDateTime(2022, 1, 6, 0, 0, 0); // The week number is based on the year with most days of the week. The week with the days from December // 27th to Januar 2nd has five days in 2021 and only two days in 2020, so it becomes Week 52 of 2021. The // week from Januar 3rd to January 9th has all it's days in 2020, so it becomes Week 1 of 2020. Assert.AreEqual(52, dec27.WeekNumber, "December 27th"); Assert.AreEqual(52, dec28.WeekNumber, "December 28th"); Assert.AreEqual(52, dec29.WeekNumber, "December 29th"); Assert.AreEqual(52, dec30.WeekNumber, "December 30th"); Assert.AreEqual(52, dec31.WeekNumber, "December 31st"); Assert.AreEqual(52, jan01.WeekNumber, "January 1st"); Assert.AreEqual(52, jan02.WeekNumber, "January 2nd"); Assert.AreEqual(1, jan03.WeekNumber, "January 3rd"); Assert.AreEqual(1, jan04.WeekNumber, "January 4th"); Assert.AreEqual(1, jan05.WeekNumber, "January 5th"); Assert.AreEqual(1, jan06.WeekNumber, "January 6th"); }
internal RedirectItem(RedirectItemRow row) { _created = EssentialsDateTime.FromUnixTimestamp(row.Created); _updated = EssentialsDateTime.FromUnixTimestamp(row.Updated); _linkMode = EnumUtils.ParseEnum(row.LinkMode, RedirectLinkMode.Content); Row = row; }
public static string ToIso8601(EssentialsDateTime timestamp) { if (timestamp == null) { throw new ArgumentNullException(nameof(timestamp)); } return(Iso8601Utils.ToString(timestamp.DateTime)); }
/// <summary> /// Initializes a new instance from the specified <paramref name="date"/>. /// </summary> /// <param name="date">An instance of <see cref="EssentialsDateTime"/> representing the full date.</param> #pragma warning disable 618 public EssentialsPartialDate(EssentialsDateTime date) { #pragma warning restore 618 Year = date == null ? 0 : date.Year; Month = date == null ? 0 : date.Month; Day = date == null ? 0 : date.Day; DateTime = new DateTime(Year == 0 ? 1 : Year, Month == 0 ? 1 : Month, Day == 0 ? 1 : Day); }
/// <summary> /// Initializes a new instance from the specified <paramref name="timestamp"/>. /// </summary> /// <param name="timestamp">A timestamp represented by an instance of <see cref="EssentialsDateTime"/>.</param> public EssentialsDateYear(EssentialsDateTime timestamp) { if (timestamp == null) { throw new ArgumentNullException(nameof(timestamp)); } Year = timestamp.Year; }
public Sample(EssentialsTime time) { Time1 = Time2 = time.DateTimeOffset.DateTime; Time3 = Time4 = time.DateTimeOffset; Time5 = Time6 = new EssentialsDateTime(time.DateTimeOffset.DateTime); Time7 = Time8 = time; }
/// <summary> /// Converts the specified <paramref name="timestamp"/> to a string representation as specified by the /// <strong>RFC 822</strong> format. /// </summary> /// <param name="timestamp">The timestamp to be converted.</param> /// <returns>The timestamp formatted as a RFC 822 date string.</returns> public static string ToRfc822(EssentialsDateTime timestamp) { if (timestamp == null) { throw new ArgumentNullException(nameof(timestamp)); } return(ToRfc822(timestamp.DateTime)); }
/// <summary> /// Gets a list of posts of the user or page with the specified <paramref name="identifier"/>. /// </summary> /// <param name="identifier">The identifier (ID or alias) of the user or page.</param> /// <param name="limit">The maximum amount of posts to be returned on each page.</param> /// <param name="until">A timestamp that points to the start of the range of time-based data.</param> /// <param name="fields">A collection of the fields that should be returned by the API.</param> /// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns> public IHttpResponse GetPosts(string identifier, int limit, EssentialsDateTime until, FacebookFieldsCollection fields) { if (String.IsNullOrWhiteSpace(identifier)) { throw new ArgumentNullException(nameof(identifier), "A Facebook identifier (ID or alias) must be specified."); } return(GetPosts(new FacebookGetPostsOptions(identifier, limit, until, fields))); }
public void GetDaysInMonth() { // 2020 was a leap year, 2021 isn't EssentialsDateTime y2020 = new EssentialsDateTime(2020, 2, 26, 0, 0, 0); EssentialsDateTime y2021 = new EssentialsDateTime(2021, 2, 26, 0, 0, 0); Assert.AreEqual(29, y2020.DaysInMonth); Assert.AreEqual(28, y2021.DaysInMonth); }
/// <summary> /// Gets the current age, from the specified <paramref name="dateOfBirth"/>. The age is calculated based on /// <paramref name="dt"/>. /// </summary> /// <param name="dateOfBirth">The date of birth.</param> /// <param name="dt">The date used for calculating the age.</param> /// <returns>The age based on the specified <paramref name="dateOfBirth"/> at the moment of /// <paramref name="dt"/>.</returns> public static int GetAge(EssentialsDateTime dateOfBirth, EssentialsDateTime dt) { int age = dt.Year - dateOfBirth.Year; if (dt.Month < dateOfBirth.Month || (dt.Month == dateOfBirth.Month && dt.Day < dateOfBirth.Day)) { age--; } return(age); }
/// <summary> /// Gets a list of news items for the app (game) matching the specified <paramref name="appId"/>. /// </summary> /// <param name="appId">The app ID.</param> /// <param name="maxLength">The maximum length of the <see cref="SteamNewsItem.Contents"/> field.</param> /// <param name="endDate">The end date.</param> /// <param name="count">The maximum amount of news items to be returned.</param> /// <param name="feeds">The name of the feeds from which news items should be returned. If not specified, news items of all feeds will be returned.</param> /// <returns>An instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public SocialHttpResponse GetNewsForApp(uint appId, uint maxLength = 0, EssentialsDateTime endDate = null, uint count = 0, string[] feeds = null) { return(GetNewsForApp(new SteamGetNewsForAppOptions { AppId = appId, MaxLength = maxLength, EndDate = endDate, Count = count, Feeds = feeds })); }
/// <summary> /// Writes the JSON representation of the object. /// </summary> /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param> /// <param name="value">The value.</param> /// <param name="serializer">The calling serializer.</param> public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { if (!(value is EssentialsDateTime)) { return; } EssentialsDateTime dt = (EssentialsDateTime)value; base.WriteJson(writer, dt.DateTime, serializer); }
public void IsLeapYear() { // 2020 was a leap year, 2021 isn't EssentialsDateTime y2020 = new EssentialsDateTime(2020, 9, 27, 0, 0, 0); EssentialsDateTime y2021 = new EssentialsDateTime(2021, 9, 27, 0, 0, 0); Assert.IsTrue(y2020.IsLeapYear); Assert.IsFalse(y2021.IsLeapYear); }
private WindowsLiveUser(JObject obj) : base(obj) { Id = obj.GetString("id"); Name = obj.GetString("name"); FirstName = obj.GetString("first_name"); LastName = obj.GetString("last_name"); Gender = obj.GetString("gender"); Link = obj.GetString("link"); Emails = obj.GetObject("emails", WindowsLiveUserEmailsInfo.Parse); Locale = obj.GetString("locale"); UpdatedTime = obj.GetString("updated_time", EssentialsDateTime.Parse); }
public static int GetTimeDiffInHours(this EssentialsDateTime timestamp) { if (timestamp == null || timestamp.IsZero) { return(0); } var seconds = EssentialsDateTime.CurrentUnixTimestamp - timestamp.UnixTimestamp; var hours = (long)Math.Floor(seconds / 60.0 / 60.0); return((int)hours); }
/// <summary> /// Writes the JSON representation of the object. /// </summary> /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param> /// <param name="value">The value.</param> /// <param name="serializer">The calling serializer.</param> public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { if (value is EssentialsDateTime) { EssentialsDateTime dt = (EssentialsDateTime) value; writer.WriteValue(dt.UnixTimestamp); } if (value is DateTime) { DateTime dt = (DateTime) value; writer.WriteValue(TimeUtils.GetUnixTimeFromDateTime(dt)); } }
public void EssentialsTime() { #pragma warning disable 618 EssentialsDateTime t = new EssentialsDateTime(2019, 9, 14); EssentialsTime a = new EssentialsTime(2020, 9, 13, TimeSpan.Zero); EssentialsTime b = new EssentialsTime(2020, 9, 14, TimeSpan.Zero); EssentialsTime c = new EssentialsTime(2020, 9, 15, TimeSpan.Zero); Assert.AreEqual(0, TimeUtils.GetAge(t, a)); Assert.AreEqual(1, TimeUtils.GetAge(t, b)); Assert.AreEqual(1, TimeUtils.GetAge(t, c)); #pragma warning restore 618 }
public void DateTimeOffset() { #pragma warning disable 618 EssentialsDateTime t = new EssentialsDateTime(2019, 9, 14); DateTimeOffset a = new DateTimeOffset(2020, 9, 13, 0, 0, 0, TimeSpan.Zero); DateTimeOffset b = new DateTimeOffset(2020, 9, 14, 0, 0, 0, TimeSpan.Zero); DateTimeOffset c = new DateTimeOffset(2020, 9, 15, 0, 0, 0, TimeSpan.Zero); Assert.AreEqual(0, TimeUtils.GetAge(t, a)); Assert.AreEqual(1, TimeUtils.GetAge(t, b)); Assert.AreEqual(1, TimeUtils.GetAge(t, c)); #pragma warning restore 618 }
public void GetDayOfWeek() { EssentialsDateTime monday = new EssentialsDateTime(2021, 9, 27, 0, 0, 0); EssentialsDateTime tuesday = new EssentialsDateTime(2021, 9, 28, 0, 0, 0); EssentialsDateTime wednesday = new EssentialsDateTime(2021, 9, 29, 0, 0, 0); EssentialsDateTime thursday = new EssentialsDateTime(2021, 9, 30, 0, 0, 0); EssentialsDateTime friday = new EssentialsDateTime(2021, 10, 1, 0, 0, 0); EssentialsDateTime saturday = new EssentialsDateTime(2021, 10, 2, 0, 0, 0); EssentialsDateTime sunday = new EssentialsDateTime(2021, 10, 3, 0, 0, 0); Assert.AreEqual(DayOfWeek.Monday, monday.DayOfWeek); Assert.AreEqual(DayOfWeek.Tuesday, tuesday.DayOfWeek); Assert.AreEqual(DayOfWeek.Wednesday, wednesday.DayOfWeek); Assert.AreEqual(DayOfWeek.Thursday, thursday.DayOfWeek); Assert.AreEqual(DayOfWeek.Friday, friday.DayOfWeek); Assert.AreEqual(DayOfWeek.Saturday, saturday.DayOfWeek); Assert.AreEqual(DayOfWeek.Sunday, sunday.DayOfWeek); }
public void IsWeekend() { EssentialsDateTime monday = new EssentialsDateTime(2021, 9, 27, 0, 0, 0); EssentialsDateTime tuesday = new EssentialsDateTime(2021, 9, 28, 0, 0, 0); EssentialsDateTime wednesday = new EssentialsDateTime(2021, 9, 29, 0, 0, 0); EssentialsDateTime thursday = new EssentialsDateTime(2021, 9, 30, 0, 0, 0); EssentialsDateTime friday = new EssentialsDateTime(2021, 10, 1, 0, 0, 0); EssentialsDateTime saturday = new EssentialsDateTime(2021, 10, 2, 0, 0, 0); EssentialsDateTime sunday = new EssentialsDateTime(2021, 10, 3, 0, 0, 0); Assert.IsFalse(monday.IsWeekend); Assert.IsFalse(tuesday.IsWeekend); Assert.IsFalse(wednesday.IsWeekend); Assert.IsFalse(thursday.IsWeekend); Assert.IsFalse(friday.IsWeekend); Assert.IsTrue(saturday.IsWeekend); Assert.IsTrue(sunday.IsWeekend); }
/// <summary> /// Initializes a new instance based on the specified <paramref name="obj"/>. /// </summary> /// <param name="obj">The instance of <see cref="JObject"/> representing the object.</param> private FacebookAlbum(JObject obj) : base(obj) { Id = obj.GetString("id"); CanUpload = obj.GetBoolean("can_upload"); Count = obj.GetInt32("count"); CoverPhoto = obj.GetObject("cover_photo", FacebookAlbumCoverPhoto.Parse); CreatedTime = obj.GetString("created_time", EssentialsDateTime.Parse); Description = obj.GetString("description"); Event = obj.GetObject("event", FacebookEvent.Parse); From = obj.GetObject("from", FacebookFrom.Parse); Link = obj.GetString("link"); Location = obj.GetString("location"); Name = obj.GetString("name"); Place = obj.GetObject("place", FacebookPlace.Parse); Privacy = obj.GetString("privacy"); Type = obj.GetEnum("type", FacebookAlbumType.Unspecified); UpdatedTime = obj.GetString("updated_time", EssentialsDateTime.Parse); }
public void GetDay() { EssentialsDateTime monday = new EssentialsDateTime(2021, 9, 27, 0, 0, 0); EssentialsDateTime tuesday = new EssentialsDateTime(2021, 9, 28, 0, 0, 0); EssentialsDateTime wednesday = new EssentialsDateTime(2021, 9, 29, 0, 0, 0); EssentialsDateTime thursday = new EssentialsDateTime(2021, 9, 30, 0, 0, 0); EssentialsDateTime friday = new EssentialsDateTime(2021, 10, 1, 0, 0, 0); EssentialsDateTime saturday = new EssentialsDateTime(2021, 10, 2, 0, 0, 0); EssentialsDateTime sunday = new EssentialsDateTime(2021, 10, 3, 0, 0, 0); Assert.AreEqual(27, monday.Day); Assert.AreEqual(28, tuesday.Day); Assert.AreEqual(29, wednesday.Day); Assert.AreEqual(30, thursday.Day); Assert.AreEqual(1, friday.Day); Assert.AreEqual(2, saturday.Day); Assert.AreEqual(3, sunday.Day); }
// TODO: Add support for the "with_tags" property #endregion #region Constructors private FacebookPost(JObject obj) : base(obj) { Id = obj.GetString("id"); AdminCreator = obj.GetObject("admin_creator", FacebookEntity.Parse); Application = obj.GetObject("application", FacebookApplication.Parse); Attachments = obj.GetObject("attachments", FacebookPostAttachments.Parse); // TODO: Add support for the "call_to_action" property // TODO: Add support for the "can_reply_privately" property Caption = obj.GetString("caption"); CreatedTime = obj.GetString("created_time", EssentialsDateTime.Parse); Description = obj.GetString("description"); // TODO: Add support for the "feed_targeting" property From = obj.GetObject("from", FacebookProfile.Parse); FullPicture = obj.GetString("full_picture"); Icon = obj.GetString("icon"); // TODO: Add support for the "instagram_eligibility" property IsHidden = obj.GetBoolean(FacebookPostFields.IsHidden.Name); // TODO: Add support for the "is_instagram_eligible" property IsPublished = obj.GetBoolean("is_published"); Link = obj.GetString("link"); Message = obj.GetString("message"); MessageTags = obj.GetArrayItems("message_tags", FacebookProfileTag.Parse); Name = obj.GetString("name"); ObjectId = obj.GetString("object_id"); ParentId = obj.GetString("parent_id"); PermalinkUrl = obj.GetString("permalink_url"); Picture = obj.GetString("picture"); Place = obj.GetObject("place", FacebookPlace.Parse); Privacy = obj.GetObject("privacy", FacebookPostPrivacy.Parse); Properties = obj.GetArray("properties", FacebookPostProperty.Parse) ?? new FacebookPostProperty[0]; Shares = obj.GetObject("shares", FacebookShares.Parse); Likes = obj.GetObject("likes", FacebookLikesCollection.Parse); Comments = obj.GetObject("comments", FacebookCommentsCollection.Parse); Source = obj.GetString("source"); StatusType = obj.GetEnum("status_type", FacebookPostStatusType.NotSpecified); Story = obj.GetString("story"); StoryTags = obj.GetArrayItems("story_tags", FacebookProfileTag.Parse); // TODO: Add support for the "targeting" property // TODO: Add support for the "to" property Type = obj.GetEnum("type", FacebookPostType.NotSpecified); UpdatedTime = obj.GetString("updated_time", EssentialsDateTime.Parse); // TODO: Add support for the "with_tags" property }