-
Notifications
You must be signed in to change notification settings - Fork 964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for time expressions ("from now", "in", "since", "ago") #816
Comments
Hi, good suggestion, but I found 2 problems: FirstI think we can not leave the user defines the time expression directly in the
My proposal is create a provider class ( public class DateTimeExpressionProvider
{
public TimeExpressionFuture GetFutureTimeExpression() => throw null;
public TimeExpressionPast GetPastTimeExpression() => throw null;
}
public class CustomTimeExpressionProvider : DateTimeExpressionProvider
{
public override TimeExpressionFuture GetFutureTimeExpression()
{
return TimeExpressionFuture.FromNow;
}
public override TimeExpressionPast GetPastTimeExpression()
{
return TimeExpressionPast.Ago;
}
} Then pass it to var customTimeExpressionProvider = new CustomTimeExpressionProvider()
DateTime.UtcNow.AddHours(-2).Humanize(customTimeExpressionProvider) => “2 hours ago”
SecondI researched and I think
And the
I would like to open a discussion about the use of |
It would be perfect to do that! Thanks a lot! |
Just came across this. When this feature is implemented, would I be able to call the static method :
and be able to have future value result as "in 2 hours" instead of "2 hours from now" ? |
Hi,
Thank you for this great library ! Such a usefull tool !
I was thinking maybe it will be a great add to be able to choose between "since" and "ago" in order to express ifferents meanings for past expression and be able to choose between "from now" and "in" in order to express differents meanings for future expression.
Today there is no options it's "ago" and that's all:
DateTime.UtcNow.AddHours(-30).Humanize() => "yesterday"
DateTime.UtcNow.AddHours(-2).Humanize() => "2 hours ago"
But maybe it can be more with a choice between "since" and "ago":
DateTime.UtcNow.AddHours(-30).Humanize(PastTimeExpression.Ago) => "yesterday"
DateTime.UtcNow.AddHours(-2).Humanize(PastTimeExpression.Ago) => "2 hours ago"
DateTime.UtcNow.AddHours(-30).Humanize(PastTimeExpression.Since) => "since yesterday"
DateTime.UtcNow.AddHours(-2).Humanize(PastTimeExpression.Since) => "since 2 hours"
Today there is no options it's "from now" and that's all:
DateTime.UtcNow.AddHours(30).Humanize() => "tomorrow"
DateTime.UtcNow.AddHours(2).Humanize() => "2 hours from now"
"tomorrow" is a specific case because in a way to express "from now" it should be "until tomorrow" because only "tomorrow" is more compatible with a "in" case
But maybe it can be more with a choice between "from now" and "in":
DateTime.UtcNow.AddHours(30).Humanize(FutureTimeExpression.FromNow) => "until tomorrow"
DateTime.UtcNow.AddHours(2).Humanize(FutureTimeExpression.FromNow) => "2 hours from now"
DateTime.UtcNow.AddHours(30).Humanize(FutureTimeExpression.In) => "tomorrow"
DateTime.UtcNow.AddHours(2).Humanize(FutureTimeExpression.In) => "in 2 hours"
Some examples :
"Your flight will take off in 2 hours"
"Our plane is flying since 4 hours"
"We will waiting our next flight 3 hours from now"
"We land 1 hour ago"
I think it's not easy to add it but it can be a great add to allow to express those differents meanings with time expressions.
Thank you
The text was updated successfully, but these errors were encountered: