Skip to content

Commit

Permalink
update Timeline.tsx in BottomDock to use datetime traits
Browse files Browse the repository at this point in the history
  • Loading branch information
sixlighthouses committed Jul 13, 2023
1 parent 045f9d1 commit 6c85660
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
6 changes: 6 additions & 0 deletions lib/Core/DateUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function getOffsetMinutes(timeZone: string): number {
const [hoursString, minutesString] = timeZone.split(":");
const hours = parseInt(hoursString);
const minutes = parseInt(minutesString);
return hours * 60 + minutes;
}
42 changes: 38 additions & 4 deletions lib/ReactViews/BottomDock/Timeline/Timeline.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import JulianDate from "terriajs-cesium/Source/Core/JulianDate";
import CommonStrata from "../../../Models/Definition/CommonStrata";
import withControlledVisibility from "../../HOCs/withControlledVisibility";
import CesiumTimeline from "./CesiumTimeline";
import { getOffsetMinutes } from "../../../Core/DateUtils";
// import { formatDateTime } from "./DateFormats";
import DateTimePicker from "./DateTimePicker";
import Styles from "./timeline.scss";
Expand Down Expand Up @@ -67,7 +68,26 @@ class Timeline extends React.Component {
}
const { t } = this.props;

const jsDate = JulianDate.toDate(catalogItem.currentTimeAsJulianDate);
let jsDate;

if (defined(catalogItem.timeZone)) {
try {
const offset = getOffsetMinutes(catalogItem.timeZone);
const offsetTime = new JulianDate();
const adjTime = JulianDate.addMinutes(
catalogItem.currentDiscreteJulianDate,
offset,
offsetTime
);
jsDate = JulianDate.toDate(adjTime);
} catch (e) {
console.log(e);
jsDate = JulianDate.toDate(catalogItem.currentTimeAsJulianDate);
}
} else {
jsDate = JulianDate.toDate(catalogItem.currentTimeAsJulianDate);
}

const timelineStack = this.props.terria.timelineStack;
let currentTime;
if (defined(timelineStack.top) && defined(timelineStack.top.dateFormat)) {
Expand All @@ -76,9 +96,23 @@ class Timeline extends React.Component {
this.props.terria.timelineStack.top.dateFormat
);
} else {
console.log(catalogItem.timeZone);
// currentTime = formatDateTime(jsDate, this.props.locale);
currentTime = dateFormat(jsDate, "isoDate");
if (defined(catalogItem.timeZone)) {
const offset = getOffsetMinutes(catalogItem.timeZone);
const offsetTime = new JulianDate();
const adjTime = JulianDate.addMinutes(
catalogItem.currentDiscreteJulianDate,
offset,
offsetTime
);
if (defined(catalogItem.dateFormat)) {
console.log("adjusted dateFormat", catalogItem.dateFormat);
currentTime = dateFormat(adjTime, catalogItem.dateFormat);
} else {
currentTime = dateFormat(adjTime, "isoDate");
}
} else {
currentTime = dateFormat(jsDate, "isoDate");
}
}

const discreteTimes = catalogItem.discreteTimesAsSortedJulianDates;
Expand Down
11 changes: 2 additions & 9 deletions lib/ReactViews/Workbench/Controls/DateTimeSelectorSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { GLYPHS, StyledIcon } from "../../../Styled/Icon";
import Spacing from "../../../Styled/Spacing";
import Text, { TextSpan } from "../../../Styled/Text";
import { formatDateTime } from "../../BottomDock/Timeline/DateFormats";
import { getOffsetMinutes } from "../../../Core/DateUtils";
import DateTimePicker from "../../BottomDock/Timeline/DateTimePicker";

interface IState {
Expand Down Expand Up @@ -128,13 +129,6 @@ class DateTimeSelectorSection extends React.Component<IProps, IState> {
event.stopPropagation();
}

getOffsetMinutes(timeZone: string) {
const [hoursString, minutesString] = timeZone.split(":");
const hours = parseInt(hoursString);
const minutes = parseInt(minutesString);
return hours * 60 + minutes;
}

render() {
const { t } = this.props;
let discreteTime;
Expand All @@ -154,7 +148,7 @@ class DateTimeSelectorSection extends React.Component<IProps, IState> {
if (isDefined(item.currentDiscreteJulianDate)) {
let time = JulianDate.toDate(item.currentDiscreteJulianDate);
if (isDefined(item.timeZone)) {
const offset = this.getOffsetMinutes(item.timeZone);
const offset = getOffsetMinutes(item.timeZone);
const offsetTime = new JulianDate();
const adjTime = JulianDate.addMinutes(
item.currentDiscreteJulianDate,
Expand All @@ -165,7 +159,6 @@ class DateTimeSelectorSection extends React.Component<IProps, IState> {
}

if (isDefined(item.dateFormat)) {
format = item.dateFormat;
discreteTime = dateFormat(time, item.dateFormat);
} else {
discreteTime = dateFormat(time, "isoDate");
Expand Down

0 comments on commit 6c85660

Please sign in to comment.