The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

56 regels
943 B

  1. import moment from 'moment';
  2. moment.updateLocale('en', {
  3. relativeTime : {
  4. future: "in %s",
  5. past: "%s ago",
  6. s: "s",
  7. m: "a minute",
  8. mm: "%dm",
  9. h: "an hour",
  10. hh: "%dh",
  11. d: "a day",
  12. dd: "%dd",
  13. M: "a month",
  14. MM: "%dmo",
  15. y: "a year",
  16. yy: "%dy"
  17. }
  18. });
  19. const RelativeTimestamp = React.createClass({
  20. getInitialState () {
  21. return {
  22. text: ''
  23. };
  24. },
  25. propTypes: {
  26. timestamp: React.PropTypes.string.isRequired
  27. },
  28. componentWillMount () {
  29. this._updateMomentText();
  30. this.interval = setInterval(this._updateMomentText, 6000);
  31. },
  32. componentWillUnmount () {
  33. clearInterval(this.interval);
  34. },
  35. _updateMomentText () {
  36. this.setState({ text: moment(this.props.timestamp).fromNow() });
  37. },
  38. render () {
  39. return (
  40. <span style={{ color: '#616b86' }}>
  41. {this.state.text}
  42. </span>
  43. );
  44. }
  45. });
  46. export default RelativeTimestamp;