In the lambda, calculate the fuzzy time by finding out how many times the time reference fits into the difference. Instead of a lambda, this could be a function call, or done inline under each conditional statement.įactoring it out into a lambda prevents repetition, while also keeping the scope contained within the function, as it will not be used anywhere else. ![]() ![]() Once a match is found, we'll pass the selected time_referece along with a string representation of the time reference to a lambda, where the response string will be built. Sites like twitter seem to work around this by using fuzzy time up until 24 hours have past, then switch to showing the month in string form along with the numeric day of the month.įollowing that method would be a good option if more granularity is required. The caveat is that is is fuzzy, meaning that if a post is 1.5 days old, it will show as posted 1 day ago. Showing the difference is also more relevant to others looking at how long ago a post was made, instead of when it was posted. Some examples of fuzzy time: 32 seconds agoĪn advantage of using the fuzzy time format is that it doesn't rely on time zones, or any particular day, month, year ordering. The fuzzy time equation: fuzzy_time = (current_time - posted_time) / time_reference Fuzzy time represents the largest integer time reference that can fit into the difference between the current time and the posted time, where the time references are seconds, minutes, days, weeks, months, and year.
0 Comments
Leave a Reply. |