Fix ordinal suffix for numbers greater than 10

This commit is contained in:
Julia Friesel
2020-09-30 20:33:21 +02:00
committed by Sofiya Tepikin
parent 77908afd60
commit e5418c32e2
3 changed files with 22 additions and 16 deletions
+2 -2
View File
@@ -7,7 +7,7 @@ import moment from 'moment'
import AppText from '../common/app-text' import AppText from '../common/app-text'
import cycleModule from '../../lib/cycle' import cycleModule from '../../lib/cycle'
import { dateEnding } from '../helpers/home' import { getOrdinalSuffix } from '../helpers/home'
import { Containers, Typography } from '../../styles' import { Containers, Typography } from '../../styles'
const CycleDayLabel = ({ height, date }) => { const CycleDayLabel = ({ height, date }) => {
@@ -18,7 +18,7 @@ const CycleDayLabel = ({ height, date }) => {
const dateFormatting = isFirstDayOfMonth ? 'MMM' : 'D' const dateFormatting = isFirstDayOfMonth ? 'MMM' : 'D'
const shortDate = moment(date, "YYYY-MM-DD").format(dateFormatting) const shortDate = moment(date, "YYYY-MM-DD").format(dateFormatting)
const ending = isFirstDayOfMonth ? const ending = isFirstDayOfMonth ?
'' : dateEnding[this.cycleDayNumber] || dateEnding['default'] '' : getOrdinalSuffix(this.cycleDayNumber)
const cycleDayLabel = cycleDayNumber ? cycleDayNumber : ' ' const cycleDayLabel = cycleDayNumber ? cycleDayNumber : ' '
return ( return (
+11 -5
View File
@@ -63,9 +63,15 @@ export function getBleedingPredictionRange(prediction) {
return (daysToEnd === 0 ? '0' : `0 - ${daysToEnd}`) return (daysToEnd === 0 ? '0' : `0 - ${daysToEnd}`)
} }
export const dateEnding = { export function getOrdinalSuffix(num) {
'1': 'st', const suffixes = {
'2': 'nd', 1: 'st',
'3': 'rd', 2: 'nd',
'default': 'th' 3: 'rd',
default: 'th'
}
const numAsString = num.toString()
const lastNumber = numAsString[numAsString.length - 1]
return suffixes[lastNumber] || suffixes.default
} }
+3 -3
View File
@@ -13,7 +13,7 @@ import Button from './common/button'
import cycleModule from '../lib/cycle' import cycleModule from '../lib/cycle'
import { getFertilityStatusForDay } from '../lib/sympto-adapter' import { getFertilityStatusForDay } from '../lib/sympto-adapter'
import { determinePredictionText, dateEnding } from './helpers/home' import { determinePredictionText, getOrdinalSuffix } from './helpers/home'
import { Colors, Fonts, Sizes, Spacing } from '../styles' import { Colors, Fonts, Sizes, Spacing } from '../styles'
import { home as labels } from '../i18n/en/labels' import { home as labels } from '../i18n/en/labels'
@@ -37,10 +37,10 @@ class Home extends Component {
const prediction = getPredictedMenses() const prediction = getPredictedMenses()
this.cycleDayText = !this.cycleDayNumber ? labels.cycleDayNotEnoughInfo this.cycleDayText = !this.cycleDayNumber ? labels.cycleDayNotEnoughInfo
: `${this.cycleDayNumber}${dateEnding[this.cycleDayNumber] || dateEnding['default']}` : `${this.cycleDayNumber}${getOrdinalSuffix(this.cycleDayNumber)}`
this.phase = phase this.phase = phase
this.phaseText = !phase ? statusText this.phaseText = !phase ? statusText
: `${phase}${dateEnding[phase] || dateEnding['default']}` : `${phase}${getOrdinalSuffix(phase)}`
this.prediction = determinePredictionText(prediction) this.prediction = determinePredictionText(prediction)
this.status = status this.status = status
this.statusText = statusText this.statusText = statusText