Skip to content

Commit f5fae39

Browse files
committed
replace getString with moment.js in CalendarEvent
1 parent 5b4917a commit f5fae39

File tree

1 file changed

+3
-31
lines changed

1 file changed

+3
-31
lines changed

views/calendar/event.js

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {
55
Text,
66
} from 'react-native'
77

8+
import moment from 'moment-timezone'
89
import * as c from '../components/colors'
9-
import padEnd from 'lodash/padEnd'
1010
import {getText, parseHtml} from '../../lib/html'
1111

1212
let styles = StyleSheet.create({
@@ -29,40 +29,12 @@ let styles = StyleSheet.create({
2929
},
3030
})
3131

32-
function getString(date) {
33-
let month = date.getMonth() + 1 // offset since JS uses 0-11, not 1-12
34-
let day = date.getDate()
35-
36-
let hours = date.getHours()
37-
let isMorning = true
38-
if (date.getHours() > 12) {
39-
hours = date.getHours() - 12
40-
isMorning = false
41-
}
42-
43-
let min = date.getMinutes()
44-
if (min.toString().length < 2) {
45-
min = padEnd(min, 2, '0')
46-
}
47-
48-
if (isMorning) {
49-
min += 'AM'
50-
} else {
51-
min += 'PM'
52-
}
53-
54-
return `${month}/${day} ${hours}:${min}`
55-
}
56-
5732
// PROPS: eventTitle, location, startTime, endTime
5833
export default function EventView(props: {eventTitle: string, location: string, startTime?: string, endTime?: string, style?: any}) {
5934
let title = getText(parseHtml(props.eventTitle))
6035

61-
let st = new Date(props.startTime)
62-
let et = new Date(props.endTime)
63-
64-
let stString = getString(st)
65-
let etString = getString(et)
36+
let stString = moment(props.startTime).format('M/D h:mma')
37+
let etString = moment(props.endTime).format('M/D h:mma')
6638

6739
let showTimes = props.startTime && props.endTime
6840
let showLocation = Boolean(props.location)

0 commit comments

Comments
 (0)