Skip to content

Commit

Permalink
feat: format dates (english only for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaclennan committed Apr 26, 2019
1 parent 77bc4e4 commit d998a60
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/frontend/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@ export function matchPreset(
if (!categoryId) return;
return presets.get(categoryId);
}

export function formatDate(dateString: string): string {
const date = new Date(dateString);
const options = {
weekday: "short",
year: "numeric",
month: "short",
day: "numeric"
};
return date.toLocaleString(options);
}
3 changes: 2 additions & 1 deletion src/frontend/screens/Observation/ObservationView.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
EditIcon,
CategoryIcon
} from "../../sharedComponents/icons";
import { formatDate } from "../../lib/utils";
import type { PresetWithFields } from "../../context/PresetsContext";
import type { Observation } from "../../context/ObservationsContext";

Expand Down Expand Up @@ -45,7 +46,7 @@ const ObservationView = ({ observation, preset = {} }: ODVProps) => {
<FormattedCoords lon={lon} lat={lat} style={styles.positionText} />
</View>
)}
<Text style={styles.time}>{observation.created_at}</Text>
<Text style={styles.time}>{formatDate(observation.created_at)}</Text>
<View style={styles.section}>
<Text style={styles.textNotes}>{observation.value.tags.notes}</Text>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { View, FlatList, Dimensions, StyleSheet } from "react-native";
import memoize from "memoize-one";

import ObservationListItem from "./ObservationListItem";
import { formatDate } from "../../lib/utils";
import type {
Observation,
ObservationsMap
Expand Down Expand Up @@ -67,7 +68,7 @@ const ObservationsListView = ({
style={styles.listItem}
title={name}
iconId={icon}
subtitle={created_at}
subtitle={formatDate(created_at)}
onPress={onPressObservation}
/>
);
Expand Down

0 comments on commit d998a60

Please sign in to comment.