Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.0.17 #537

Merged
merged 18 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"expo": {
"name": "TAMU SHPE",
"slug": "TAMU-SHPE",
"version": "1.0.16",
"version": "1.0.17",
"owner": "tamu-shpe",
"orientation": "portrait",
"icon": "./assets/icon.png",
Expand Down
1 change: 1 addition & 0 deletions assets/calendar-days-solid_black.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/calendar-days-solid_white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/clock-solid_black.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/clock-solid_white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/location-dot-solid_black.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/location-dot-solid_white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shpe-app",
"version": "1.0.16",
"version": "1.0.17",
"scripts": {
"start": "npx expo start --dev-client",
"test": "jest --coverage=true --verbose --bail --config ./jest.config.ts",
Expand Down
23 changes: 23 additions & 0 deletions src/api/firebaseUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,29 @@ export const getUpcomingEvents = async () => {
return events;
};

export const getWeekPastEvents = async (): Promise<SHPEEvent[]> => {
const currentTime = new Date();
const twoWeeksAgo = new Date(currentTime);
twoWeeksAgo.setDate(currentTime.getDate() - 8);

const eventsRef = collection(db, "events");
const q = query(
eventsRef,
where("endTime", "<", currentTime),
where("endTime", ">", twoWeeksAgo),
orderBy("endTime", "desc")
);

const querySnapshot = await getDocs(q);
const events: SHPEEvent[] = [];

querySnapshot.forEach(doc => {
events.push({ id: doc.id, ...doc.data() } as SHPEEvent);
});

return events;
};

export const getPastEvents = async (numLimit: number, startAfterDoc: any, setEndOfData?: (endOfData: boolean) => void) => {
const currentTime = new Date();
const eventsRef = collection(db, "events");
Expand Down
3 changes: 3 additions & 0 deletions src/components/MOTMCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ const MOTMCard: React.FC<MemberCardProp> = ({ navigation }) => {
}, [currentUser])
);

if (!MOTM) {
return null;
}

return (
<View className="mx-4">
Expand Down
119 changes: 89 additions & 30 deletions src/helpers/timeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,6 @@ export const formatTime = (date: Date): string => {
return `${hour % 12 == 0 ? 12 : hour % 12}:${minute.toString().padStart(2, '0')}${hour > 11 ? "pm" : "am"}`;
}

export const formatEventTime = (startDate: Date, endDate: Date): string => {
const startHour = startDate.getHours();
const endHour = endDate.getHours();
const startMinute = startDate.getMinutes();
const endMinute = endDate.getMinutes();

const startAmPm = startHour >= 12 ? "pm" : "am";
const endAmPm = endHour >= 12 ? "pm" : "am";

const formattedStartTime = `${startHour % 12 === 0 ? 12 : startHour % 12}:${startMinute.toString().padStart(2, '0')}`;
const formattedEndTime = `${endHour % 12 === 0 ? 12 : endHour % 12}:${endMinute.toString().padStart(2, '0')}${endAmPm}`;

if (startAmPm === endAmPm) {
return `${formattedStartTime} - ${formattedEndTime}`;
}

return `${formattedStartTime}${startAmPm} - ${formattedEndTime}`;
}


/**
* Constructs a readable string that represents the date and time of day of a given `Date` object and it's timezone offset.
* @param date
Expand All @@ -94,7 +74,26 @@ export const formatDateTime = (date: Date): string => {
return `${formatDate(date)}, ${formatTime(date)} GMT${date.getTimezoneOffset() < 0 ? "+" : "-"}${(date.getTimezoneOffset() / 60).toString().padStart(2, '0')}`
}

export const formatEventDate = (startTime: Date, endTime: Date) => {
export const formatEventDate = (startTime: Date, endTime: Date): string => {
// Formats the date as "Monday, September 16"
const formatFullDate = (date: Date): string => {
const options: Intl.DateTimeFormatOptions = { weekday: 'long', month: 'long', day: 'numeric' };
return date.toLocaleDateString('en-US', options);
};

// Formats the date as "September 16"
const formatMonthDay = (date: Date): string => {
const options: Intl.DateTimeFormatOptions = { month: 'long', day: 'numeric' };
return date.toLocaleDateString('en-US', options);
};

// Formats the date as "September 16, 2024"
const formatMonthDayYear = (date: Date): string => {
const options: Intl.DateTimeFormatOptions = { month: 'long', day: 'numeric', year: 'numeric' };
return date.toLocaleDateString('en-US', options);
};

// Check if start and end times are on the same day, month, or year
const isSameDay = startTime.getDate() === endTime.getDate() &&
startTime.getMonth() === endTime.getMonth() &&
startTime.getFullYear() === endTime.getFullYear();
Expand All @@ -103,22 +102,82 @@ export const formatEventDate = (startTime: Date, endTime: Date) => {
startTime.getFullYear() === endTime.getFullYear();

const isSameYear = startTime.getFullYear() === endTime.getFullYear();
const formatMonthDayOnly = (date: Date): string => {
const day = date.getDate();
const month = monthNames[date.getMonth()];

return `${month} ${day}`;
if (isSameDay) {
return formatFullDate(startTime); // "Monday, September 16"
} else if (isSameMonth) {
return `${formatMonthDay(startTime)} - ${endTime.getDate()}`; // "September 16 - 17"
} else if (isSameYear) {
return `${formatMonthDay(startTime)} - ${formatMonthDay(endTime)}`; // "September 16 - October 18"
} else {
return `${formatMonthDayYear(startTime)} - ${formatMonthDayYear(endTime)}`; // "December 17, 2024 - December 18, 2025"
}
};


export const formatEventDateTime = (startTime: Date, endTime: Date): string => {
// Formats the date as "Monday, September 16"
const formatFullDate = (date: Date): string => {
const options: Intl.DateTimeFormatOptions = { weekday: 'long', month: 'long', day: 'numeric' };
return date.toLocaleDateString('en-US', options);
};

// Formats the date as "September 16"
const formatMonthDay = (date: Date): string => {
const options: Intl.DateTimeFormatOptions = { month: 'long', day: 'numeric' };
return date.toLocaleDateString('en-US', options);
};

// Formats the date as "September 16, 2024"
const formatMonthDayYear = (date: Date): string => {
const options: Intl.DateTimeFormatOptions = { month: 'long', day: 'numeric', year: 'numeric' };
return date.toLocaleDateString('en-US', options);
};

// Formats the time as "1:00pm"
const formatTime = (date: Date): string => {
const hours = date.getHours();
const minutes = date.getMinutes();
const amPm = hours >= 12 ? 'pm' : 'am';
const formattedHour = hours % 12 === 0 ? 12 : hours % 12;
const formattedMinute = minutes.toString().padStart(2, '0');
return `${formattedHour}:${formattedMinute}${amPm}`;
};

const isSameDay = startTime.getDate() === endTime.getDate() &&
startTime.getMonth() === endTime.getMonth() &&
startTime.getFullYear() === endTime.getFullYear();

const isSameMonth = startTime.getMonth() === endTime.getMonth() &&
startTime.getFullYear() === endTime.getFullYear();

const isSameYear = startTime.getFullYear() === endTime.getFullYear();

if (isSameDay) {
return `${formatDate(startTime)}`;
return `${formatFullDate(startTime)}, ${formatTime(startTime)} - ${formatTime(endTime)}`; // "Monday, September 16, 1:00pm - 2:00pm"
} else if (isSameMonth) {
return `${formatMonthDayOnly(startTime)} - ${endTime.getDate()}`;
return `${formatMonthDay(startTime)}, ${formatTime(startTime)} - ${formatMonthDay(endTime)}, ${formatTime(endTime)}`; // "September 16, 1:00pm - September 17, 2:00pm"
} else if (isSameYear) {
return `${formatMonthDayOnly(startTime)} - ${formatDate(endTime)}`;
return `${formatMonthDay(startTime)}, ${formatTime(startTime)} - ${formatMonthDay(endTime)}, ${formatTime(endTime)}`; // "September 16, 1:00pm - October 18, 2:00pm"
} else {
return `${formatDateWithYear(startTime)} - ${formatDateWithYear(endTime)}`;
return `${formatMonthDayYear(startTime)}, ${formatTime(startTime)} - ${formatMonthDayYear(endTime)}, ${formatTime(endTime)}`; // "December 17, 2024, 1:00pm - December 18, 2025, 2:00pm"
}
};
};

export const formatEventTime = (startDate: Date, endDate: Date): string => {
// Helper function to format time
const formatTime = (date: Date): string => {
const hours = date.getHours();
const minutes = date.getMinutes();
const amPm = hours >= 12 ? 'pm' : 'am';
const formattedHour = hours % 12 === 0 ? 12 : hours % 12;
const formattedMinute = minutes.toString().padStart(2, '0');
return `${formattedHour}:${formattedMinute}${amPm}`;
};

const startFormatted = formatTime(startDate);
const endFormatted = formatTime(endDate);

// Format time range output
return `${startFormatted} - ${endFormatted}`;
};
6 changes: 0 additions & 6 deletions src/screens/committees/CommitteeInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,6 @@ const CommitteeInfo: React.FC<CommitteeInfoScreenRouteProps> = ({ route, navigat
<View className='mt-10'>
<View className='flex-row justify-between items-center mb-4'>
<Text className={`text-2xl font-bold ${darkMode ? "text-white" : "text-black"}`}>Upcoming Events</Text>
<TouchableOpacity
className='px-4'
onPress={() => navigation.getParent()?.navigate('EventsTab', { screen: 'EventsScreen', params: { filter: EventType.COMMITTEE_MEETING, committee: firebaseDocName } })}
>
<Text className='text-lg text-primary-blue font-semibold'>View all</Text>
</TouchableOpacity>
</View>

<View
Expand Down
Loading
Loading