Skip to content

Commit

Permalink
Merge pull request #10 from concord-consortium/188382072-change-defau…
Browse files Browse the repository at this point in the history
…lt-date-to-today

fix: Change default end date to today [PT-188382072]
  • Loading branch information
dougmartin authored Oct 19, 2024
2 parents d7a5988 + 19b7bee commit af8a729
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/components/location-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { kAttrCategories, kChildCollectionAttributes, kDataContextName } from ".
import { AttributeCategory, ILocation, Units } from "../types";
import { LocationPicker } from "./location-picker";
import { formatLatLongNumber } from "../utils/daylight-utils";
import { oneYearAgoFromYesterday, yesterday } from "../utils/date-utils";
import { defaultEnd, defaultStart } from "../utils/date-utils";
import { findNearestLocation } from "../utils/geonameSearch";

import ProgressIndicator from "../assets/images/progress-indicator.svg";
Expand All @@ -20,8 +20,8 @@ type DataStatus = "" | "retrieving" | "retrieved" | "incomplete" | "error";
export const LocationTab: React.FC = () => {
const [latitude, setLatitude] = useState("");
const [longitude, setLongitude] = useState("");
const [startDate, setStartDate] = useState(oneYearAgoFromYesterday);
const [endDate, setEndDate] = useState(yesterday);
const [startDate, setStartDate] = useState(defaultEnd);
const [endDate, setEndDate] = useState(defaultStart);
const [units, setUnits] = useState<Units>("imperial");
const [locationSearch, setLocationSearch] = useState<string>("");
const [selectedAttrCategories, setSelectedAttrCategories] = useState<AttributeCategory[]>(kAttrCategories);
Expand Down
14 changes: 8 additions & 6 deletions src/utils/date-utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const padNumber = (num: number): string => num.toString().padStart(2, "0");
const dateToString = (d: Date) => `${d.getFullYear()}-${padNumber(d.getMonth() + 1)}-${padNumber(d.getDate())}`

const yesterdayDate = new Date();
yesterdayDate.setDate(yesterdayDate.getDate() - 1);
const oneYearAgoFromYesterdayDate = new Date(yesterdayDate);
oneYearAgoFromYesterdayDate.setFullYear(oneYearAgoFromYesterdayDate.getFullYear() - 1);
// default to end today
const defaultEndDate = new Date();

export const yesterday = dateToString(yesterdayDate);
export const oneYearAgoFromYesterday = dateToString(oneYearAgoFromYesterdayDate);
// default to start one year ago
const defaultStartDate = new Date(defaultEndDate);
defaultStartDate.setFullYear(defaultStartDate.getFullYear() - 1);

export const defaultStart = dateToString(defaultEndDate);
export const defaultEnd = dateToString(defaultStartDate);

0 comments on commit af8a729

Please sign in to comment.