Work item customization ( duration of work item state)

Looking for a java script that calculates time duration of specific state in the workflow.
For e.g., The workflow has the following states:
Open,
Approval,
Review,
Close
If the work item is in Review state, I would like to calculate the duration of Review (How long the work item was in Review State) before transiting to Close state.
In the help manual script is given to calculate work item age but i need to compute how long an RTC work item spends in a specific state.
Can somebody help me to write java script for the above mentioned customization?
One answer

The Data Warehouse data source has this information and you're better off reporting on this instead of putting it on the individual work item as a script. Check out the Work Item Status History end point as the start of your report - link this to the Work Item if you need other fields.
Create the report and put it on the dashboard if you want it to be public information.