public static string Humanize(DateTimeOffset input) { // this works around https://github.com/xamarin/xamarin-android/issues/2012 and https://github.com/Humanizr/Humanizer/issues/690#issuecomment-368536282 try { return(input.Humanize()); } catch (ArgumentException) { return(input.Humanize(culture: new CultureInfo("en-US"))); } }
public CommentViewModel(string title, string content, DateTimeOffset created, string avatarUrl) { Title = title; Content = content; Created = created.Humanize(); AvatarUrl = avatarUrl; }
public CommitElement(string name, string description, DateTimeOffset date, Avatar avatar) { _name = name; _description = description; _date = date.Humanize(); _avatar = avatar; }
public CommentElement(string title, string message, DateTimeOffset date, Avatar avatar) { _title = title; _message = message; _date = date.Humanize(); _avatar = avatar; }
public void Set(string title, string description, DateTimeOffset time, GitHubAvatar avatar) { TitleLabel.Text = title; ContentLabel.Text = description; TimeLabel.Text = time.Humanize(); ContentConstraint.Constant = string.IsNullOrEmpty(description) ? 0f : DefaultContentConstraintSize; MainImageView.SetAvatar(avatar); }
public void Set(string title, string description, DateTimeOffset time, GitHubAvatar avatar) { ContentConstraint.Constant = string.IsNullOrEmpty(description) ? 0f : DefaultContentConstraintSize; TitleLabel.Text = title; ContentLabel.Text = description; TimeLabel.Text = time.Humanize(); MainImageView.SetAvatar(avatar); }
public PullRequestElement(string name, DateTimeOffset time, Avatar avatar, UIImage image = null) : base(null) { _name = name; _time = time.Humanize(); _avatar = avatar; _image = image ?? Images.Avatar; }
public CommitElement(string name, string description, DateTimeOffset time, string imageUri = null, UIImage image = null) : base(null) { _name = name; _description = description; _time = time.Humanize(); _imageUri = imageUri; _image = image ?? Images.Avatar; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return((value switch { DateTime dateTime => dateTime.Humanize(), DateTimeOffset dateTimeOffset => dateTimeOffset.Humanize(), TimeSpan timeSpan => timeSpan.Humanize(precision: 3, minUnit: TimeUnit.Second), _ => value.ToString(), }).ApplyCase(LetterCasing.Sentence));
public GistItemViewModel(string title, string avatarUrl, string description, DateTimeOffset updatedAt, Action<GistItemViewModel> gotoAction) { Title = title; Description = description; UpdatedAt = updatedAt; UpdatedString = UpdatedAt.Humanize(); GoToCommand = ReactiveCommand.Create().WithSubscription(x => gotoAction(this)); Avatar = new GitHubAvatar(avatarUrl); }
public GistItemViewModel(string title, string avatarUrl, string description, DateTimeOffset updatedAt, Action <GistItemViewModel> gotoAction) { Title = title; Description = description; UpdatedAt = updatedAt; UpdatedString = UpdatedAt.Humanize(); GoToCommand = ReactiveCommand.Create().WithSubscription(x => gotoAction(this)); Avatar = new GitHubAvatar(avatarUrl); }
public object?Convert(object?value, Type targetType, object?parameter, CultureInfo culture) { return(value switch { DateTime dt => dt.Humanize(), DateTimeOffset dt => dt.Humanize(), TimeSpan ts => ts.Humanize(), _ => null, });
public NameTimeStringElement(string name, string description, DateTimeOffset time, string imageUri = null, UIImage image = null, int lines = 0) : base(null) { _name = name; _description = description; _time = time.Humanize(); _imageUri = imageUri; _image = image ?? Images.Avatar; _lines = (nint)lines; }
public void PrecisionStrategy_DifferentOffsets() { Configurator.DateTimeOffsetHumanizeStrategy = new PrecisionDateTimeOffsetHumanizeStrategy(0.75); var inputTime = new DateTimeOffset(2015, 07, 05, 03, 45, 0, new TimeSpan(2, 0, 0)); var baseTime = new DateTimeOffset(2015, 07, 05, 02, 30, 0, new TimeSpan(-5, 0, 0)); const string expectedResult = "6 hours ago"; var actualResult = inputTime.Humanize(baseTime); Assert.Equal(expectedResult, actualResult); }
public void DefaultStrategy_SameOffset() { Configurator.DateTimeOffsetHumanizeStrategy = new DefaultDateTimeOffsetHumanizeStrategy(); var inputTime = new DateTimeOffset(2015, 07, 05, 04, 0, 0, TimeSpan.Zero); var baseTime = new DateTimeOffset(2015, 07, 05, 03, 0, 0, TimeSpan.Zero); const string expectedResult = "an hour from now"; var actualResult = inputTime.Humanize(baseTime); Assert.Equal(expectedResult, actualResult); }
public void DefaultStrategy_DifferentOffsets() { Configurator.DateTimeOffsetHumanizeStrategy = new DefaultDateTimeOffsetHumanizeStrategy(); var inputTime = new DateTimeOffset(2015, 07, 05, 03, 0, 0, new TimeSpan(2, 0, 0)); var baseTime = new DateTimeOffset(2015, 07, 05, 02, 30, 0, new TimeSpan(1, 0, 0)); const string expectedResult = "30 minutes ago"; var actualResult = inputTime.Humanize(baseTime); Assert.Equal(expectedResult, actualResult); }
public void PrecisionStrategy_SameOffset() { Configurator.DateTimeOffsetHumanizeStrategy = new PrecisionDateTimeOffsetHumanizeStrategy(0.75); var inputTime = new DateTimeOffset(2015, 07, 05, 04, 0, 0, TimeSpan.Zero); var baseTime = new DateTimeOffset(2015, 07, 04, 05, 0, 0, TimeSpan.Zero); const string expectedResult = "tomorrow"; var actualResult = inputTime.Humanize(baseTime); Assert.Equal(expectedResult, actualResult); }
public NewsFeedElement(string imageUrl, DateTimeOffset time, IEnumerable<TextBlock> headerBlocks, IEnumerable<TextBlock> bodyBlocks, UIImage littleImage, Action tapped) : base(null) { Uri.TryCreate(imageUrl, UriKind.Absolute, out _imageUri); _time = time.Humanize(); _actionImage = littleImage; _tapped = tapped; var header = CreateAttributedStringFromBlocks(headerBlocks); _attributedHeader = header.Item1; _headerLinks = header.Item2; var body = CreateAttributedStringFromBlocks(bodyBlocks); _attributedBody = body.Item1; _bodyLinks = body.Item2; }
public NewsFeedElement(string imageUrl, DateTimeOffset time, IEnumerable<TextBlock> headerBlocks, IEnumerable<TextBlock> bodyBlocks, UIImage littleImage, Action tapped, bool multilined) { Uri.TryCreate(imageUrl, UriKind.Absolute, out _imageUri); _time = time.Humanize(); _actionImage = littleImage; _tapped = tapped; _multilined = multilined; var header = CreateAttributedStringFromBlocks(UIFont.PreferredBody, Theme.CurrentTheme.MainTextColor, headerBlocks); _attributedHeader = header.Item1; _headerLinks = header.Item2; var body = CreateAttributedStringFromBlocks(UIFont.PreferredSubheadline, Theme.CurrentTheme.MainSubtitleColor, bodyBlocks); _attributedBody = body.Item1; _bodyLinks = body.Item2; }
public NewsFeedElement(string imageUrl, DateTimeOffset time, IEnumerable <TextBlock> headerBlocks, IEnumerable <TextBlock> bodyBlocks, UIImage littleImage, Action tapped, bool multilined) { Uri.TryCreate(imageUrl, UriKind.Absolute, out _imageUri); _time = time.Humanize(); _actionImage = littleImage; _tapped = tapped; _multilined = multilined; var header = CreateAttributedStringFromBlocks(UIFont.PreferredBody, Theme.CurrentTheme.MainTextColor, headerBlocks); _attributedHeader = header.Item1; _headerLinks = header.Item2; var body = CreateAttributedStringFromBlocks(UIFont.PreferredSubheadline, Theme.CurrentTheme.MainSubtitleColor, bodyBlocks); _attributedBody = body.Item1; _bodyLinks = body.Item2; }
public NewsFeedElement(string imageUrl, DateTimeOffset time, IEnumerable <TextBlock> headerBlocks, IEnumerable <TextBlock> bodyBlocks, UIImage littleImage, Action tapped) : base(null) { Uri.TryCreate(imageUrl, UriKind.Absolute, out _imageUri); _time = time.Humanize(); _actionImage = littleImage; _tapped = tapped; var header = CreateAttributedStringFromBlocks(headerBlocks); _attributedHeader = header.Item1; _headerLinks = header.Item2; var body = CreateAttributedStringFromBlocks(bodyBlocks); _attributedBody = body.Item1; _bodyLinks = body.Item2; }
public void Bind(string title, string status, string priority, string assigned, DateTimeOffset lastUpdated, string id, string kind) { Caption.Text = title; Label1.Text = status; Label2.Text = priority; Label3.Text = assigned; Label4.Text = lastUpdated.Humanize(); Number.Text = "#" + id; IssueType.Text = kind; /* * if (model.CommentCount > 0) * { * var ms = model.CommentCount.ToString (); * var ssize = ms.MonoStringLength(CountFont); * var boxWidth = Math.Min (22 + ssize, 18); * AddSubview(new CounterView(model.CommentCount) { Frame = new RectangleF(Bounds.Width-30-boxWidth, Bounds.Height / 2 - 8, boxWidth, 16) }); * } */ }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { Configurator.DateTimeHumanizeStrategy = new PrecisionDateTimeHumanizeStrategy(1); if (value is DateTime) { DateTime dateTime = (DateTime)value; return(dateTime.Humanize(false)); } if (value is DateTimeOffset) { DateTimeOffset dateTimeOffset = (DateTimeOffset)value; return(dateTimeOffset.Humanize()); } return(string.Empty); }
public void Bind(string title, string status, string priority, string assigned, DateTimeOffset lastUpdated, string id, string kind) { Caption.Text = title; Label1.Text = status; Label2.Text = priority; Label3.Text = assigned; Label4.Text = lastUpdated.Humanize(); Number.Text = "#" + id; IssueType.Text = kind; /* if (model.CommentCount > 0) { var ms = model.CommentCount.ToString (); var ssize = ms.MonoStringLength(CountFont); var boxWidth = Math.Min (22 + ssize, 18); AddSubview(new CounterView(model.CommentCount) { Frame = new RectangleF(Bounds.Width-30-boxWidth, Bounds.Height / 2 - 8, boxWidth, 16) }); } */ }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(null); } ToDoItem toDoItem = (ToDoItem)value; DateTimeOffset createdDateTime = toDoItem.CreatedDateTime; DateTimeOffset endedDateTime = toDoItem.EndedDateTime; if (toDoItem.IsFinished == false) { return(createdDateTime.Humanize()); } else { return($"{endedDateTime.Humanize()} Completed"); } }
private void updateTime() => Text = date.Humanize();
/// <summary> /// Sends an event for admin approval (if <paramref name="EventType"/> is Official, it skips this step), and adds it to the database. /// </summary> /// <param name="EventType">The type of event hosting, either official or user-hosted.</param> /// <param name="Proposer">The User who proposed the event in the first place.</param> /// <param name="Release">The Time when the event is to be released to the public.</param> /// <param name="Description">The event description containing all relevant information as to partake in the event and what it consists on.</param> /// <returns>A <c>Task</c> object, which can be awaited until the method completes successfully.</returns> public async Task AddEvent(EventType EventType, IGuildUser Proposer, DateTimeOffset Release, string Description) { if (Description.Length > 1000) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("Event description too long!") .WithDescription($"Try to keep the description under 1000 characters, the current description is {Description.Length} characters long.") .SendEmbed(Context.Channel); return; } int ID = CommunityEventsDB.GenerateToken(); EventStatus Status = EventType == EventType.UserHosted ? EventStatus.Pending : EventStatus.Approved; string ReleaseTimer = await CreateEventTimer(ReleaseEventCallback, new Dictionary <string, string> { { "ID", ID.ToString() } }, (int)Release.Subtract(DateTimeOffset.Now).TotalSeconds, TimerType.Expire); string ProposalText = $"**New Event Suggestion >>>** {CommunityConfiguration.EventsNotificationMention}"; string Link = Description.GetHyperLinks().FirstOrDefault(); if (Link != null && Link.Length > 0) { ProposalText += $"\n{Link}"; } ulong ProposalMessage = 0; if (EventType == EventType.UserHosted) { IMessageChannel MessageChannel = DiscordSocketClient.GetChannel(CommunityConfiguration.EventsNotificationsChannel) as IMessageChannel; Embed EventInfo = CreateEventProposalEmbed(ID, Status, Proposer, Release.ToOffset(TimeSpan.FromHours(BotConfiguration.StandardTimeZone)), Description).Build(); IMessage Proposal = await MessageChannel.SendMessageAsync( text : ProposalText, embed : EventInfo); ProposalMessage = Proposal.Id; } CommunityEventsDB.Events.Add( new() { ID = ID, EventType = EventType, ProposerID = Proposer.Id, DateTimeProposed = DateTimeOffset.Now.ToUnixTimeSeconds(), DateTimeRelease = Release.ToUnixTimeSeconds(), Description = Description, Status = Status, ResolveReason = "", EventProposal = ProposalMessage, ReleaseTimer = ReleaseTimer }); CommunityEventsDB.SaveChanges(); await UpdateEventProposal(ID); if (EventType == EventType.Official) { await BuildEmbed(EmojiEnum.Love) .WithTitle($"Event #{ID} Successfully Programmed!") .WithDescription($"The official server event has been successfully added to the database and will be displayed in <#{CommunityConfiguration.OfficialEventsChannel}> when its release time comes. \n" + $"You can always check the information of this event with the command `{BotConfiguration.Prefix}events get id {ID}`") .AddField("Release Time: ", $"{Release:ddd', 'MMM d 'at' hh:mm tt 'UTC'z} ({Release.Humanize()})") .SendEmbed(Context.Channel); } else { await BuildEmbed(EmojiEnum.Love) .WithTitle($"Event #{ID} Successfully Suggested!") .WithDescription($"Your suggestion went through! You will be informed when it is approved or declined. You can always check the status with `{BotConfiguration.Prefix}event get id {ID}`") .AddField("Release Time: ", $"{Release:ddd', 'MMM d 'at' hh:mm tt 'UTC'z} ({Release.Humanize()})") .WithCurrentTimestamp() .SendEmbed(Context.Channel); } }
public void Nullable_ExpectSame() { DateTimeOffset? never = new DateTimeOffset(2015, 12, 7, 9, 0, 0, TimeSpan.FromHours(1)); Assert.Equal(never.Value.Humanize(), never.Humanize()); }
public void Set(string title, DateTimeOffset time, GitHubAvatar avatar) { TitleLabel.Text = title; TimeLabel.Text = time.Humanize(); MainImageView.SetAvatar(avatar); }
public static string PodcastEpisodeHumanize(this DateTimeOffset date) => date.Date == DateTime.Today.Date ? date.Humanize() : date.PodcastEpisodeDateTime();
protected virtual string Format() => Date.Humanize();
/// <summary> /// A callback method to be called when an event suggestion is approved. It sets the status to approved and handles expired events. /// </summary> /// <param name="EventID">The unique numerical ID for the target event.</param> /// <param name="Reason">The optional reason for approval of the event.</param> /// <returns>A <c>Task</c> object, which can be awaited until this method completes successfully.</returns> public async Task ApproveEventCallback(int EventID, string Reason = "") { CommunityEvent Event = GetEvent(EventID); IUser Proposer = DiscordSocketClient.GetUser(Event.ProposerID); if (Event == null) { return; } if (Event.Status == EventStatus.Expired) { if (CommunityConfiguration.FailOnOverdueApproval) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("This Event has already expired!") .WithDescription("Expired events can't be approved (FailOnOverdueApproval configuration is activated)") .WithCurrentTimestamp() .SendEmbed(Context.Channel); return; } else { await BuildEmbed(EmojiEnum.Sign) .WithTitle("This Event is overdue!") .WithDescription("The event will be released immediately (FailOnOverDueApproval configuration is off)") .WithCurrentTimestamp() .SendEmbed(Context.Channel); Event.Status = EventStatus.Approved; await ReleaseEvent(EventID); return; } } DateTimeOffset Release = DateTimeOffset.FromUnixTimeSeconds(Event.DateTimeRelease).ToOffset(TimeSpan.FromHours(BotConfiguration.StandardTimeZone)); if (!TimerService.TimerExists(Event.ReleaseTimer)) { Event.ReleaseTimer = await CreateEventTimer(ReleaseEventCallback, new Dictionary <string, string> { { "ID", Event.ID.ToString() } }, (int)Release.Subtract(DateTimeOffset.Now).TotalSeconds, TimerType.Expire); } Event.ResolveReason = Reason; Event.Status = EventStatus.Approved; await UpdateEventProposal(Event.ID); await BuildEmbed(EmojiEnum.Love) .WithTitle("Event approved for release!") .WithDescription($"Event #{Event.ID} will be released at {Release:ddd', 'MMM d 'at' hh:mm tt 'UTC'z} ({Release.Humanize()}).") .WithCurrentTimestamp() .SendDMAttachedEmbed(Context.Channel, BotConfiguration, Proposer, BuildEmbed(EmojiEnum.Love) .WithTitle("Your Event has been Approved!") .WithDescription(Event.Description) .AddField(Reason.Length > 0, "Reason: ", Reason) .AddField("Release Time:", $"{Release:ddd', 'MMM d 'at' hh:mm tt 'UTC'z}")); CommunityEventsDB.SaveChanges(); }
public void Nullable_ExpectSame() { DateTimeOffset?never = new DateTimeOffset(2015, 12, 7, 9, 0, 0, TimeSpan.FromHours(1)); Assert.Equal(never.Value.Humanize(), never.Humanize()); }