date-fns#setHours TypeScript Examples
The following examples show how to use
date-fns#setHours.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: time.ts From nyxo-app with GNU General Public License v3.0 | 6 votes |
export function minutesToHoursString(
minutes: number | undefined,
longFormat?: boolean
): string {
if (!minutes) {
return '-'
}
const time = setMinutes(setHours(new Date(), 0), minutes)
if (longFormat) {
return `${format(time, 'h')} ${translate('Hours')} ${format(
time,
'mm'
)}min `
}
return `${format(time, 'h')} h ${format(time, 'mm')} min`
}
Example #2
Source File: time.ts From nyxo-app with GNU General Public License v3.0 | 5 votes |
export function getTimeInString(minutes: number): string {
if (!minutes) {
return '-'
}
const time = setMinutes(setHours(new Date(), 0), minutes)
return `${format(time, 'h')} h ${format(time, 'mm')}`
}
Example #3
Source File: SleepTime.tsx From nyxo-app with GNU General Public License v3.0 | 4 votes |
SleepTime: FC<Props> = ({
hasData,
x,
y,
timeAsleep = 0,
timeInBed = 0,
sleepEnd,
sleepStart,
bedStart,
bedEnd
}) => {
if (!hasData) {
return (
<G>
<ThemedText
x={x}
y={y - 15}
textAnchor="middle"
fontFamily="Montserrat-Bold"
fontWeight="bold"
alignmentBaseline="central"
fontSize="28">
{translate('CLOCK_NO_DATA_TITLE')}
</ThemedText>
<ThemedText
x={x}
y={y + 15}
textAnchor="middle"
fontFamily="Montserrat-Medium"
fontWeight="bold"
textLength="30"
alignmentBaseline="central"
fontSize="13">
{translate('CLOCK_NO_DATA_SUBTITLE')}
</ThemedText>
</G>
)
}
const inBed = setMinutes(setHours(new Date(), 0), timeInBed ?? 0)
const asleep = setMinutes(setHours(new Date(), 0), timeAsleep ?? 0)
const timeToUseStart = sleepStart || bedStart
const timeToUseEnd = sleepEnd || bedEnd
const formattedStart = timeToUseStart
? format(new Date(timeToUseStart), 'HH:mm')
: ''
const formattedEnd = timeToUseEnd
? format(new Date(timeToUseEnd), 'HH:mm')
: ''
const hourValueBed = format(inBed, 'H')
const minuteValueBed = format(inBed, 'mm')
const hourValueSleep = format(asleep, 'H')
const minuteValueSleep = format(asleep, 'mm')
const valueToShow = timeAsleep
? `${hourValueSleep}:${minuteValueSleep}`
: `${hourValueBed}:${minuteValueBed}`
const string = `${formattedStart} - ${formattedEnd}`
return (
<G>
<SVGText
id="inbed"
x={x}
y={y + 30}
textAnchor="middle"
fontFamily="Montserrat-Medium"
fontWeight="bold"
textLength={100}
alignmentBaseline="central"
fontSize="13"
fill={colors.darkBlue}>
{string}
</SVGText>
<StartText
id="asleep"
x={x}
y={y}
fontFamily="Montserrat-Bold"
textAnchor="middle"
alignmentBaseline="central"
fontSize="42"
fontWeight="bold">
{valueToShow}
</StartText>
</G>
)
}