Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit 18cf5df

Browse files
committed
Payment prefs uses relative local and ISO 8601 dates
- Add [moment.js](https://github.com/moment/moment/) which localizes time/date things Fix #4294 Auditors: @jkup @mrose17 Test Plan: 1. In Prefeences > Payments, see Status and look for the "Next contribution: in {n} days". 2. In Payment history, check that contribution dates are in ISO 8601 format (YYYY-MM-DD). 3. Also look near the bottom for "Next contribution :in {n} days". 4. Change Browser language in General then restart browser 5. Go to Payments, see Status and find localized "in {n} days string"
1 parent c0a506d commit 18cf5df

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

js/about/preferences.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const getSetting = require('../settings').getSetting
2222
const SortableTable = require('../components/sortableTable')
2323
const Button = require('../components/button')
2424
const searchProviders = require('../data/searchProviders')
25+
const moment = require('moment')
2526

2627
const adblock = appConfig.resourceNames.ADBLOCK
2728
const cookieblock = appConfig.resourceNames.COOKIEBLOCK
@@ -825,9 +826,10 @@ class PaymentsTab extends ImmutableComponent {
825826
if (!ledgerData.get('reconcileStamp')) {
826827
return null
827828
}
828-
let nextReconcileDate = formattedDateFromTimestamp(ledgerData.get('reconcileStamp'))
829-
let l10nDataArgs = {
830-
reconcileDate: nextReconcileDate
829+
const timestamp = ledgerData.get('reconcileStamp')
830+
const nextReconcileDateRelative = formattedTimeFromNow(timestamp)
831+
const l10nDataArgs = {
832+
reconcileDate: nextReconcileDateRelative
831833
}
832834
return <div className='paymentHistoryFooter'>
833835
<div className='nextPaymentSubmission'>
@@ -842,9 +844,10 @@ class PaymentsTab extends ImmutableComponent {
842844
if (!ledgerData.get('reconcileStamp')) {
843845
return null
844846
}
845-
const nextReconcileDate = formattedDateFromTimestamp(ledgerData.get('reconcileStamp'))
847+
const timestamp = ledgerData.get('reconcileStamp')
848+
const nextReconcileDateRelative = formattedTimeFromNow(timestamp)
846849
const l10nDataArgs = {
847-
reconcileDate: nextReconcileDate
850+
reconcileDate: nextReconcileDateRelative
848851
}
849852
return <div className='nextReconcileDate' data-l10n-args={JSON.stringify(l10nDataArgs)} data-l10n-id='statusNextReconcileDate' />
850853
}
@@ -1385,7 +1388,8 @@ class AboutPreferences extends React.Component {
13851388
ipc.on(messages.FLASH_UPDATED, (e, flashInstalled) => {
13861389
this.setState({ flashInstalled })
13871390
})
1388-
ipc.on(messages.LANGUAGE, (e, {languageCodes}) => {
1391+
ipc.on(messages.LANGUAGE, (e, {langCode, languageCodes}) => {
1392+
moment.locale(langCode)
13891393
this.setState({ languageCodes })
13901394
})
13911395
ipc.send(messages.REQUEST_LANGUAGE)
@@ -1512,9 +1516,12 @@ class AboutPreferences extends React.Component {
15121516
}
15131517
}
15141518

1515-
let formattedDateFromTimestamp = function (timestamp) {
1516-
var date = new Date(timestamp)
1517-
return date.toLocaleDateString()
1519+
function formattedDateFromTimestamp (timestamp) {
1520+
return moment(new Date(timestamp)).format('YYYY-MM-DD')
1521+
}
1522+
1523+
function formattedTimeFromNow (timestamp) {
1524+
return moment(new Date(timestamp)).fromNow()
15181525
}
15191526

15201527
module.exports = <AboutPreferences />

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"ledger-geoip": "^0.8.72",
9595
"ledger-publisher": "^0.8.74",
9696
"lru_cache": "^1.0.0",
97+
"moment": "^2.15.1",
9798
"qr-image": "^3.1.0",
9899
"random-lib": "2.1.0",
99100
"react": "^15.0.1",

0 commit comments

Comments
 (0)