@grafana/data#TIME_FORMAT TypeScript Examples
The following examples show how to use
@grafana/data#TIME_FORMAT.
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: mapper.ts From grafana-chinese with Apache License 2.0 | 6 votes |
mapRangeToTimeOption = (range: TimeRange, timeZone?: TimeZone): TimeOption => {
const formattedFrom = stringToDateTime(range.from, false, timeZone).format(TIME_FORMAT);
const formattedTo = stringToDateTime(range.to, true, timeZone).format(TIME_FORMAT);
const from = dateTimeToString(range.from, timeZone);
const to = dateTimeToString(range.to, timeZone);
return {
from,
to,
section: 3,
display: `${formattedFrom} to ${formattedTo}`,
};
}
Example #2
Source File: mapper.ts From grafana-chinese with Apache License 2.0 | 6 votes |
stringToDateTime = (value: string | DateTime, roundUp?: boolean, timeZone?: TimeZone): DateTime => {
if (isDateTime(value)) {
if (timeZone === 'utc') {
return value.utc();
}
return value;
}
if (value.indexOf('now') !== -1) {
if (!dateMath.isValid(value)) {
return dateTime();
}
const parsed = dateMath.parse(value, roundUp, timeZone);
return parsed || dateTime();
}
return dateTimeForTimeZone(timeZone, value, TIME_FORMAT);
}
Example #3
Source File: mapper.ts From grafana-chinese with Apache License 2.0 | 6 votes |
dateTimeToString = (value: DateTime, timeZone?: TimeZone): string => {
if (!isDateTime(value)) {
return value;
}
const isUtc = timeZone === 'utc';
if (isUtc) {
return value.utc().format(TIME_FORMAT);
}
return value.format(TIME_FORMAT);
}
Example #4
Source File: time.ts From grafana-chinese with Apache License 2.0 | 6 votes |
stringToDateTimeType = (value: string | DateTime, roundUp?: boolean, timeZone?: TimeZone): DateTime => {
if (isDateTime(value)) {
return value;
}
if (value.indexOf('now') !== -1) {
if (!dateMath.isValid(value)) {
return dateTime();
}
const parsed = dateMath.parse(value, roundUp, timeZone);
return parsed || dateTime();
}
return dateTimeForTimeZone(timeZone, value, TIME_FORMAT);
}
Example #5
Source File: TimePicker.tsx From grafana-chinese with Apache License 2.0 | 5 votes |
TimePickerTooltip = ({ timeRange }: { timeRange: TimeRange }) => (
<>
{timeRange.from.format(TIME_FORMAT)}
<div className="text-center">to</div>
{timeRange.to.format(TIME_FORMAT)}
</>
)
Example #6
Source File: TimePickerCalendar.tsx From grafana-chinese with Apache License 2.0 | 5 votes |
function valueToInput(value: Date | Date[], onChange: (from: string, to: string) => void): void {
const [from, to] = value;
const fromAsString = dateTime(from).format(TIME_FORMAT);
const toAsString = dateTime(to).format(TIME_FORMAT);
return onChange(fromAsString, toAsString);
}
Example #7
Source File: TimeRangeForm.tsx From grafana-chinese with Apache License 2.0 | 5 votes |
function valueAsString(value: DateTime | string): string {
if (isDateTime(value)) {
return value.format(TIME_FORMAT);
}
return value;
}