From 35d91d589dd3f0dbc3481d70f9120c262088d245 Mon Sep 17 00:00:00 2001 From: Carolina Capetillo Date: Tue, 10 Dec 2024 12:35:22 -0800 Subject: [PATCH 1/9] takes formattime and formatdatemmddyy and combines it with formatdatetime --- src/utils/formatTime.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/utils/formatTime.js b/src/utils/formatTime.js index 81ba74e..d147975 100644 --- a/src/utils/formatTime.js +++ b/src/utils/formatTime.js @@ -1,13 +1,11 @@ -function formatDate (dateString, options) { +// formats a date based on the options provided +function formatDateTime (dateString, options) { const date = new Date(dateString) - options = { year: 'numeric', month: 'long', day: 'numeric' } - return date.toLocaleDateString('en-US', options) -} - -function formatTime (timeString) { - const date = new Date(timeString) - const options = { hour: 'numeric', minute: 'numeric' } - return date.toLocaleTimeString('en-US', options) + if (options && (options.hour || options.minute)) { + return date.toLocaleTimeString('en-US', options) + } else { + return date.toLocaleDateString('en-US', options) + } } function formatToUTC (dateTime) { @@ -50,10 +48,4 @@ function calculateSessionCountdown (session) { return Math.floor((countdown - currentTime) / 1000) } -function formatDateMMDDYY (dateString) { - const date = new Date(dateString) - const options = { month: '2-digit', day: '2-digit', year: '2-digit' } - return date.toLocaleDateString('en-US', options) -} - -export { formatDate, formatTime, formatToUTC, formatCountdown, calculateSessionCountdown, formatDateMMDDYY } +export { formatDateTime, formatToUTC, formatCountdown, calculateSessionCountdown } From a662342d2a6d48e7bf636308b4cdf522d7245bae Mon Sep 17 00:00:00 2001 From: Carolina Capetillo Date: Tue, 10 Dec 2024 12:38:49 -0800 Subject: [PATCH 2/9] Revert "takes formattime and formatdatemmddyy and combines it with formatdatetime" This reverts commit 35d91d589dd3f0dbc3481d70f9120c262088d245. ff = only --- src/utils/formatTime.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/utils/formatTime.js b/src/utils/formatTime.js index d147975..81ba74e 100644 --- a/src/utils/formatTime.js +++ b/src/utils/formatTime.js @@ -1,11 +1,13 @@ -// formats a date based on the options provided -function formatDateTime (dateString, options) { +function formatDate (dateString, options) { const date = new Date(dateString) - if (options && (options.hour || options.minute)) { - return date.toLocaleTimeString('en-US', options) - } else { - return date.toLocaleDateString('en-US', options) - } + options = { year: 'numeric', month: 'long', day: 'numeric' } + return date.toLocaleDateString('en-US', options) +} + +function formatTime (timeString) { + const date = new Date(timeString) + const options = { hour: 'numeric', minute: 'numeric' } + return date.toLocaleTimeString('en-US', options) } function formatToUTC (dateTime) { @@ -48,4 +50,10 @@ function calculateSessionCountdown (session) { return Math.floor((countdown - currentTime) / 1000) } -export { formatDateTime, formatToUTC, formatCountdown, calculateSessionCountdown } +function formatDateMMDDYY (dateString) { + const date = new Date(dateString) + const options = { month: '2-digit', day: '2-digit', year: '2-digit' } + return date.toLocaleDateString('en-US', options) +} + +export { formatDate, formatTime, formatToUTC, formatCountdown, calculateSessionCountdown, formatDateMMDDYY } From 8389e3f00b19c34fb00f57216808ac8837e782a5 Mon Sep 17 00:00:00 2001 From: Carolina Capetillo Date: Tue, 10 Dec 2024 12:40:19 -0800 Subject: [PATCH 3/9] Revert "Revert "takes formattime and formatdatemmddyy and combines it with formatdatetime"" This reverts commit a662342d2a6d48e7bf636308b4cdf522d7245bae. --- src/utils/formatTime.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/utils/formatTime.js b/src/utils/formatTime.js index 81ba74e..d147975 100644 --- a/src/utils/formatTime.js +++ b/src/utils/formatTime.js @@ -1,13 +1,11 @@ -function formatDate (dateString, options) { +// formats a date based on the options provided +function formatDateTime (dateString, options) { const date = new Date(dateString) - options = { year: 'numeric', month: 'long', day: 'numeric' } - return date.toLocaleDateString('en-US', options) -} - -function formatTime (timeString) { - const date = new Date(timeString) - const options = { hour: 'numeric', minute: 'numeric' } - return date.toLocaleTimeString('en-US', options) + if (options && (options.hour || options.minute)) { + return date.toLocaleTimeString('en-US', options) + } else { + return date.toLocaleDateString('en-US', options) + } } function formatToUTC (dateTime) { @@ -50,10 +48,4 @@ function calculateSessionCountdown (session) { return Math.floor((countdown - currentTime) / 1000) } -function formatDateMMDDYY (dateString) { - const date = new Date(dateString) - const options = { month: '2-digit', day: '2-digit', year: '2-digit' } - return date.toLocaleDateString('en-US', options) -} - -export { formatDate, formatTime, formatToUTC, formatCountdown, calculateSessionCountdown, formatDateMMDDYY } +export { formatDateTime, formatToUTC, formatCountdown, calculateSessionCountdown } From e507c242e050847ad0f6cc41556ced55db9d3254 Mon Sep 17 00:00:00 2001 From: Carolina Capetillo Date: Tue, 10 Dec 2024 12:46:07 -0800 Subject: [PATCH 4/9] updates tests --- src/tests/unit/utils/formatTime.test.js | 36 ++++++++++++------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/tests/unit/utils/formatTime.test.js b/src/tests/unit/utils/formatTime.test.js index aa84813..ee23807 100644 --- a/src/tests/unit/utils/formatTime.test.js +++ b/src/tests/unit/utils/formatTime.test.js @@ -1,39 +1,37 @@ import { describe, it, expect } from 'vitest' -import { formatDate, formatTime, formatToUTC, formatCountdown, calculateSessionCountdown } from '../../../utils/formatTime' +import { formatDateTime, formatToUTC, formatCountdown, calculateSessionCountdown } from '../../../utils/formatTime' describe('formatUtils.js', () => { - describe('formatDate', () => { + describe('formatDateTime', () => { it('formats a date string to "Month Day, Year" format', () => { - const date = '2024-08-15T00:00:00Z' - const expectedDate = formatDate(new Date(date).toISOString()) - expect(formatDate(date)).toBe(expectedDate) + const date = '2024-08-15T00:00:00' + const expectedDate = 'August 15, 2024' + expect(formatDateTime(date, { year: 'numeric', month: 'long', day: 'numeric' })).toBe(expectedDate) }) - it('formats a local date string to "Month Day, Year" format', () => { - const date = 'Wed Aug 21 2024 16:15:00 GMT-0700 (Pacific Daylight Time)' - const expectedDate = formatDate(new Date(date).toISOString()) - expect(formatDate(date)).toBe(expectedDate) - }) - }) - - describe('formatTime', () => { it('formats a UTC time string to "Hour:Minute AM/PM" format', () => { - const time = '2024-08-15T15:30:00Z' - const expectedTime = formatTime(new Date(time).toISOString()) - expect(formatTime(time)).toBe(expectedTime) + const time = '2024-08-15T15:30:00' + const expectedTime = '3:30 PM' + expect(formatDateTime(time, { hour: 'numeric', minute: 'numeric' })).toBe(expectedTime) }) it('formats a local time string to "Hour:Minute AM/PM" format', () => { const time = 'Wed Aug 21 2024 16:15:00 GMT-0700 (Pacific Daylight Time)' - const expectedTime = formatTime(new Date(time).toISOString()) - expect(formatTime(time)).toBe(expectedTime) + const expectedTime = '4:15 PM' + expect(formatDateTime(time, { hour: 'numeric', minute: 'numeric' })).toBe(expectedTime) + }) + + it('formats a date string to "MM/DD/YY" format', () => { + const date = '2024-12-25T00:00:00' + const expectedDate = '12/25/24' + expect(formatDateTime(date, { month: '2-digit', day: '2-digit', year: '2-digit' })).toBe(expectedDate) }) }) describe('formatToUTC', () => { it('converts a date-time string to UTC format', () => { const dateTime = 'Wed Aug 15 2024 08:30:00 GMT-0700 (Pacific Daylight Time)' - const expectedUTC = new Date(dateTime).toISOString().split('.')[0] + 'Z' + const expectedUTC = '2024-08-15T15:30:00Z' expect(formatToUTC(dateTime)).toBe(expectedUTC) }) From 4a9b0ccb22088ba9816a850cb0fbf24066dc2ea4 Mon Sep 17 00:00:00 2001 From: Carolina Capetillo Date: Tue, 10 Dec 2024 12:46:27 -0800 Subject: [PATCH 5/9] updates formattime or formatdate to formatdatetime --- src/components/Dashboard/ObservationList.vue | 4 ++-- src/components/Dashboard/UpcomingBookings.vue | 4 ++-- src/components/Images/MyGallery.vue | 4 ++-- src/components/RealTimeInterface/TimePicker.vue | 8 +++----- src/components/Views/ObservationDetailsView.vue | 4 ++-- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/components/Dashboard/ObservationList.vue b/src/components/Dashboard/ObservationList.vue index 3544257..b135a22 100644 --- a/src/components/Dashboard/ObservationList.vue +++ b/src/components/Dashboard/ObservationList.vue @@ -1,5 +1,5 @@