Skip to content

Commit

Permalink
Merge branch 'diaryServices-rewrite' of https://github.com/the-bay-ka…
Browse files Browse the repository at this point in the history
…y/e-mission-phone into diaryServices-rewrite
  • Loading branch information
JGreenlee committed Dec 4, 2023
2 parents 650564a + e3dc66f commit 1cb28c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions www/__tests__/diaryHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import initializedI18next from '../js/i18nextInit';
window['i18next'] = initializedI18next;

it('returns a formatted date', () => {
expect(getFormattedDate('2023-09-18T00:00:00-07:00')).toBe('Mon September 18, 2023');
expect(getFormattedDate('2023-09-18T00:00:00-07:00')).toBe('Mon, September 18, 2023');
expect(getFormattedDate('')).toBeUndefined();
expect(getFormattedDate('2023-09-18T00:00:00-07:00', '2023-09-21T00:00:00-07:00')).toBe(
'Mon September 18, 2023 - Thu September 21, 2023',
'Mon, September 18, 2023 - Thu, September 21, 2023',
);
});

Expand Down
7 changes: 3 additions & 4 deletions www/js/diary/diaryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function getFormattedDate(beginFmtTime: string, endFmtTime?: string) {
day: '2-digit',
year: 'numeric',
});
return tConversion.replace(',', '');
return tConversion;
}

/**
Expand Down Expand Up @@ -152,10 +152,9 @@ export function getFormattedTimeRange(beginFmtTime: string, endFmtTime: string)
const beginTime = DateTime.fromISO(beginFmtTime, { setZone: true });
const endTime = DateTime.fromISO(endFmtTime, { setZone: true });
const range = endTime.diff(beginTime, ['hours', 'minutes']);
const unitsToDisplay = range.hours < 1 ? ['m'] : ['h'];
return humanizeDuration(range.as('milliseconds'), {
language: i18next.language,
units: unitsToDisplay,
largest: 1,
round: true,
});
}
Expand Down Expand Up @@ -196,5 +195,5 @@ export function getLocalTimeString(dt) {
hour: dt.hour,
minute: dt.minute,
});
return dateTime.toFormat('h:mm a');
return dateTime.toLocaleString(DateTime.TIME_SIMPLE);
}
24 changes: 12 additions & 12 deletions www/js/diary/timelineHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ const points2TripProps = function (locationPoints) {
const startTime = DateTime.fromSeconds(startPoint.data.ts).setZone(startPoint.metadata.time_zone);
const endTime = DateTime.fromSeconds(endPoint.data.ts).setZone(endPoint.metadata.time_zone);

const speeds = [],
dists = [];
var loc, locLatLng;
const speeds = [];
const dists = [];
let loc, locLatLng;
locationPoints.forEach((pt) => {
const ptLatLng = L.latLng([pt.data.latitude, pt.data.longitude]);
if (loc) {
Expand Down Expand Up @@ -354,7 +354,7 @@ const transitionTrip2TripObj = function (trip) {
);
};

var filteredLocationList = sortedLocationList.filter(retainInRange);
const filteredLocationList = sortedLocationList.filter(retainInRange);

// Fix for https://github.com/e-mission/e-mission-docs/issues/417
if (filteredLocationList.length == 0) {
Expand Down Expand Up @@ -440,11 +440,11 @@ const isEndingTransition = function (transWrapper) {
* Let's abstract this out into our own minor state machine.
*/
const transitions2Trips = function (transitionList: Array<ServerData<TripTransition>>) {
var inTrip = false;
var tripList = [];
var currStartTransitionIndex = -1;
var currEndTransitionIndex = -1;
var processedUntil = 0;
let inTrip = false;
const tripList = [];
let currStartTransitionIndex = -1;
let currEndTransitionIndex = -1;
let processedUntil = 0;

while (processedUntil < transitionList.length) {
// Logger.log("searching within list = "+JSON.stringify(transitionList.slice(processedUntil)));
Expand Down Expand Up @@ -510,7 +510,7 @@ const linkTrips = function (trip1, trip2) {
};

export const readUnprocessedTrips = function (startTs, endTs, lastProcessedTrip) {
var tq = { key: 'write_ts', startTs, endTs };
const tq = { key: 'write_ts', startTs, endTs };
logDebug(
'about to query for unprocessed trips from ' +
DateTime.fromSeconds(tq.startTs).toLocaleString(DateTime.DATETIME_MED) +
Expand All @@ -530,7 +530,7 @@ export const readUnprocessedTrips = function (startTs, endTs, lastProcessedTrip)
tripsList.forEach(function (trip) {
logDebug(JSON.stringify(trip, null, 2));
});
var tripFillPromises = tripsList.map(transitionTrip2TripObj);
const tripFillPromises = tripsList.map(transitionTrip2TripObj);
return Promise.all(tripFillPromises).then(function (raw_trip_gj_list: UnprocessedTrip[]) {
// Now we need to link up the trips. linking unprocessed trips
// to one another is fairly simple, but we need to link the
Expand All @@ -551,7 +551,7 @@ export const readUnprocessedTrips = function (startTs, endTs, lastProcessedTrip)
`after filtering undefined and distance < 100, trip_gj_list size = ${trip_gj_list.length}`,
);
// Link 0th trip to first, first to second, ...
for (var i = 0; i < trip_gj_list.length - 1; i++) {
for (let i = 0; i < trip_gj_list.length - 1; i++) {
linkTrips(trip_gj_list[i], trip_gj_list[i + 1]);
}
logDebug(`finished linking trips for list of size ${trip_gj_list.length}`);
Expand Down

0 comments on commit 1cb28c6

Please sign in to comment.