Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Fix NTP clock for c71 #247

Merged
merged 1 commit into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/old/clock/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@ export interface ClockProps {
customStyle?: ClockTheme
}

interface TimeComponent {
type: string,
value: string
}

export interface ClockState {
currentTime: Array<{type: string, value: string}>
currentTime: Array<TimeComponent>
date: Date
}

function isDayPeriod (timeComponent: TimeComponent): boolean {
return timeComponent.type.toLowerCase() === 'dayperiod'
}

class Clock extends React.PureComponent<ClockProps, ClockState> {
constructor (props: ClockProps) {
super(props)
Expand All @@ -44,7 +53,7 @@ class Clock extends React.PureComponent<ClockProps, ClockState> {
// hide blank strings
return null
}
} else if (component.type === 'dayperiod') {
} else if (isDayPeriod(component)) {
// hide day-period (AM / PM), it's rendered in a separate component
return null
}
Expand All @@ -54,7 +63,7 @@ class Clock extends React.PureComponent<ClockProps, ClockState> {

get formattedTimePeriod () {
const time: any = this.state.currentTime
const period = time.find((component: {type: string}) => component.type === 'dayperiod')
const period = time.find(isDayPeriod)
return period ? period.value : ''
}

Expand Down
6 changes: 6 additions & 0 deletions stories/old/views.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import * as React from 'react'
// TBD import Clock from '../components/clock'
import Page from '../../src/old/page'
import { DataBlock, DataItem } from '../../src/old/dataBlock'
import Clock from '../../src/old/clock'

storiesOf('Old/Views', module)
.addDecorator(withKnobs)
Expand Down Expand Up @@ -73,3 +74,8 @@ storiesOf('Old/Views', module)
</DataBlock>
)
})
.add('Clock', () => {
return (
<Clock />
)
})