- Rename app: Waseel (name, slug, scheme waseel://, com.waseel.app ids, splash) - Payments: replace Stripe with Areeba hosted checkout (create/verify API routes, lib/areeba.ts, WebBrowser-based payment flow) - Maps: migrate address autocomplete to Places API (New), drop legacy library - Web support: map stub for web (native maps are iOS/Android only) - Auth: keep email + Google OAuth; fix OAuth redirect for Expo Go - Add scripts/seed-db.mjs (schema + Lebanese driver seed) - Pin Expo SDK 51 compatible package versions
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import type { Ride } from "@/types/type";
|
|
|
|
export const sortRides = (rides: Ride[]): Ride[] => {
|
|
const result = rides.sort((a, b) => {
|
|
const dateA = new Date(`${a.created_at}T${a.ride_time}`);
|
|
const dateB = new Date(`${b.created_at}T${b.ride_time}`);
|
|
return dateB.getTime() - dateA.getTime();
|
|
});
|
|
|
|
return result.reverse();
|
|
};
|
|
|
|
export function formatTime(minutes: number): string {
|
|
const formattedMinutes = +minutes?.toFixed(0) || 0;
|
|
|
|
if (formattedMinutes < 60) {
|
|
return `${minutes} min`;
|
|
} else {
|
|
const hours = Math.floor(formattedMinutes / 60);
|
|
const remainingMinutes = formattedMinutes % 60;
|
|
return `${hours}h ${remainingMinutes}m`;
|
|
}
|
|
}
|
|
|
|
export function formatDate(dateString: string): string {
|
|
const date = new Date(dateString);
|
|
const day = date.getDate();
|
|
const monthNames = [
|
|
"Jan",
|
|
"Feb",
|
|
"Mar",
|
|
"Apr",
|
|
"May",
|
|
"Jun",
|
|
"Jul",
|
|
"Aug",
|
|
"Sep",
|
|
"Oct",
|
|
"Nov",
|
|
"Dec",
|
|
];
|
|
const month = monthNames[date.getMonth()];
|
|
const year = date.getFullYear();
|
|
|
|
return `${day < 10 ? "0" + day : day} ${month} ${year}`;
|
|
}
|
|
|
|
// Normalizes a Lebanese phone number to E.164 (+961...).
|
|
export function normalizePhone(raw: string): string {
|
|
const cleaned = raw.replace(/[^\d+]/g, "");
|
|
|
|
if (cleaned.startsWith("+")) return cleaned;
|
|
|
|
return `+961${cleaned.replace(/^0+/, "")}`;
|
|
}
|