Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Widgets] Timezone support via timeZone #2663

Open
3 tasks
diehbria opened this issue Mar 7, 2024 · 3 comments
Open
3 tasks

[Widgets] Timezone support via timeZone #2663

diehbria opened this issue Mar 7, 2024 · 3 comments
Labels
3 pts Assigned to HM Work that is being assisted on by HM Current sprint enhancement New feature or request

Comments

@diehbria
Copy link
Contributor

diehbria commented Mar 7, 2024

This task is to add timezone support for the shared widgets of IoT App Kit.

Add a new optional property, timeZone?: string;. This will be used to format dates into a different timezone than the where the one the user is in.

Implementation details:
We want to use https://date-fns.org/ to format dates.

const { utcToZonedTime, format } = require("date-fns-tz");

// https://date-fns.org/v3.6.0/docs/Time-Zones#date-fns-tz
// converts a utc date to a formatted string in a specific timeZone
const formatDate = (dateTime: number, { timeZone, pattern }: { timeZone: string; pattern: string; }) => {
  const zonedDate = utcToZonedTime(new Date(dateTime), timeZone);
  const formattedDate = format(zonedDate, pattern, { timeZone });

  return formattedDate;
};

How to handle timezones in echarts - apache/echarts#14453

How to handle dates in our React components -

// Helper components for use in a React Context
export type DateTimeFormatContextOptions = {
  timeZone: string;
};
export const DateTimeFormatContext = React.createContext<DateTimeFormatContextOptions>({
  timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
});

export type DateTimeOptions = {
  dateTime: number;
  pattern?: string;
};
export const DateTime = ({ dateTime, pattern }: DateTimeOptions) => {
  const dateTimeFormatPattern = pattern ?? 'yyy-MM-dd hh:mm:ss a';
  const { timeZone } = useContext(DateTimeFormatContext);

  return <>{ formatDate(dateTime, { timeZone, pattern: dateTimeFormatPattern }) }</>;
};

Default: the user's current timeZone as provided by the browser. Intl.DateTimeFormat().resolvedOptions().timeZone

For KPI, Status, make sure the bottom timestamp displayed on the widget reflects the updated timezone
Screenshot 2024-03-08 at 8 06 03 AM

For resource explorer, ensure that all places which display timestamps of data as a result of searches, reflects the timezone offset.

For XY Plot, ensure the bottom timestamp displayed reflects the timezone offset, the data point tooltip, as well as the X-Axis labels, and the timestamps shown within the legend and the trend cursor column headers.

Expected API behavior

  • When timeZone is undefined, use browser timeZone.
  • When timeZone is "America/Denver", The date should be display in Mountain Daylight Time (GMT-6).

Acceptance criteria

@diehbria diehbria added enhancement New feature or request Assigned to HM Work that is being assisted on by HM Current sprint 3 pts labels Mar 7, 2024
@tracy-french
Copy link
Contributor

tracy-french commented Mar 8, 2024

Questions:

  • Where to add time zone to the table?
  • What to do with the offset value?

@diehbria
Copy link
Contributor Author

diehbria commented Mar 8, 2024

updated ticket, no changes required for table, additional clarification added for other widgets.

@tracy-french
Copy link
Contributor

Updated ticket with expected API behavior to clarify.

@jmbuss jmbuss changed the title [Widgets] Timezone support via getTimeOffset [Widgets] Timezone support via timeZone Mar 19, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue Mar 27, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue Apr 1, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue Apr 1, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue Apr 2, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue Apr 2, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue Apr 2, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue Apr 3, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue Apr 4, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue Apr 4, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue Apr 4, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue Apr 4, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue Apr 19, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue Apr 19, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue Apr 30, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue May 2, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue May 2, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue May 3, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue May 3, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue May 6, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue May 6, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue May 7, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue May 8, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue May 21, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue May 22, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue May 22, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue May 22, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue May 22, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue May 22, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue May 22, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue May 22, 2024
Chandru-HM pushed a commit to Chandru-HM/iot-app-kit that referenced this issue May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 pts Assigned to HM Work that is being assisted on by HM Current sprint enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants