Facebook-like "time since" calculation algorithm - facebook

On Facebook, each comment or other user event has a timestamp. But it is not listed as a simple date, but presented in a form of a human-friendly string. For example if right now it is 08:38 and the comment was made at 08:31, Facebook doesn't just tell you the time, but says "7 minutes ago".
Is there an open source implementation of Facebook algorithm (or similar) that takes a data of event, a current date and tells in a human-friendly form how long has it been since?

Pretty date http://ejohn.org/projects/javascript-pretty-date/ is a good javascript library for this

You could dig into timeago jQuery plugin's source code to study.

What I think that should be the best is this :
Store the timestamp when the comment is made (eg- 3:45 12-10-2012)
Get the current system time
Get the differnce between the two .i.e (current time -comment time ) .
Most of the languages provide the datediff method . Like in PHP you can use it like this

Related

Rundeck time format

In the "Activity for jobs' page in Rundeck the execution time has a relative time field (example: "Today at 10:15 AM" or "Last Sunday at 4:51 AM") after the timestamp.
It is easy to change the date format of the timestamp by adding jobslist...format[.ko] in the i18n/messages.properties file.
It seems impossible however to change the format of the relative time message. It seems to be hard-coded in en_US with AM/PM which doesn't look too good in in non-English-speaking countries. The format is always the same regardless of the ?lang=xx parameter or the default language in the browser. Interestingly, other objects (like hovering over the field with the mouse and the duration get translated).
Has anyone successfully changed this?
Example. See the duration field
I have been trying this with the docker images (4.8.0, 4.9.0 and SNAPSHOT)
I've looked at the source code and apparently this lies somewhere in the moment.js code.
In some parts, the date formats are hard coded as you say, please add your use case on this thread.

I'm new to ionic, can anyone help me . I'm using ionic 1 .

I'm new to ionic , I want to record the last date when the app is refreshed by an user and need to show the same value in UI. The value should come as one hour back, 2 hours back and so forth ....if the app is refreshed yesterday then it should say yesterday. Even if u tell me a function then i will be good to go. Thank You.
You could use moment.js, which provides you with functions for obtaining the current timestamp - moment.now() - and to parse it into human-readable strings - moment('1496239022').fromNow().
You can even choose the locale so the human-readable strings are properly translated - moment.locale()
In essence, you would save the refresh time using moment.now() (how or where you save it is up to you - you can use localStorage if you want) and then use moment.js to show the time.
thnx alot for this solution, I solved the problem using a different method. I created variables to store current time and saved it in an array . And compared them to print time difference where in time-diff function has if-else condition to print it to be minute hour and so on. ! :) I will try ur solution now.And will let u know if it works !.Thanx again !

In Jaspersoft Studio, how do I use the DATEFORMAT() function?

Here's a screenshot:
Here's a screenshot http://www.coletrumbo.com/wp-content/uploads/2015/05/dateformat-1024x575.png
I'm trying to turn the current date into July 1st of the current year using DATEFORMAT(). I learned how to do that in MySQL from this question, and I hoped it would work similarly in Jaspersoft Studio- turns out date_format( curdate(), '%Y-07-01' ) doesn't translate into
DATEFORMAT( TODAY(), '%Y-07-01' ) or DATEFORMAT( TODAY(), YY/07/01 ). Neither worked.
I could keep trying to get creative and hopefully find something that works, but I'd rather actually understand how to use DATEFORMAT().
I checked the Jaspersoft Studio User Guide, but it's not there. From the prompts on the screen, it makes a lot of sense, but I just can't figure out the "format pattern" that I'm allowed to apply, or even how to correctly write any format pattern at all. Also, this conveniently named question, DateFormat Pattern, didn't actually help at all. And community.jaspersoft.com/answers is kind of a joke in my opinion. When I checked it a couple days ago, it was filled with spam linking to live hockey games.
Thanks in advance. I'm sure this is a beginner level question, so I feel dumb asking it, and I feel like I'm wasting other people's space and time with it because I should already know. So I really appreciate your willingness to care.
I am using the following to get the todays date in a danish format
"Dato: "+new java.text.SimpleDateFormat("dd MMMM yyyy",new
Locale("da", "DK")).format(new Date())
you can find the source code for the DateTime functions directly in JR repository: https://sourceforge.net/p/jasperreports/code/ci/master/tree/jasperreports/demo/samples/functions/src/net/sf/jasperreports/functions/standard/DateTimeFunctions.java
As you can see the code is fairly simple and relies on the Joda Time library.
Therefore the second parameter you are trying to enter is a String, while the first one is a Date object.
Indeed something that could work for you is an expression like this DATEFORMAT(TODAY(), "07-01-YYYY")
Regards,
Massimo.

How to get list of occurrence dates from iCalendar RRULE

I have the iCalendar file with RRULE for occurrences. How to get the list of dates on which the event will be occurring as per given start date and RRULE in the iCal file.
In Java, I want to write a method which should take start date and RRULE and return me the list of occurrence dates. Please help with simple solution or directions.
There is a Java library specifically for parsing RRULEs called google-rfc-2445.
The following link contains an example using the library where you supply a start date along with an RRULE and it prints out the dates.
http://google-rfc-2445.googlecode.com/svn/trunk/README.html
I do not have a chance to read README because of 404 - The requested URL /svn/trunk/README.html was not found on this server. If you have an example to show, please share it. I've found another solution lib-recur. lib-recur is shared via maven repository.

Change article_custom so that 'past' doesn't exclude an event on the current date

I'm using textpattern and trying to display a list of upcoming events. I'm using article_custom.
<txp:article_custom
form="eventshome"
limit="4"
time="future"
sort="Posted
section="events" />
The issue I have is that this is supposed to show events coming up but using 'future' means that when an event is on the current date it's not showing (it's not future anymore). Both 'past' and 'future' time options seem to exclude the current date. That means people coming on the site don't see an event on that day which is a bit of an issue.
I've had a quick look around the code but can't seem to work out how to change the SQL statement so that future includes the current date.
Any help appreciated.
Its a bit oldie, but since i've just fixed the same issue, i thought i could provide my very simple soution to this matter.
What i did was simply set article date and time to its date and 25:59:59 time, so its visible all day on current day, but disappears immeadetly when day changes.
Since i didn't want to type those times always again and again, i run small javascript on article page which sets those automaticly to fields.
You can try plugin smd_calendar - http://stefdawson.com/sw/plugins/smd_calendar
it supports a lot of methods to display upcomming and past events.