A Privacy-Friendly Event Planner in JavaScript: Time Zones, Conflicts, and Budget
An event-discovery interface often starts with cards: a poster, a date, a category, and a ticket price. The difficulty appears when someone selects several cards. Two concerts may overlap, a free event may still require
An event-discovery interface often starts with cards: a poster, a date, a category, and a ticket price. The difficulty appears when someone selects several cards. Two concerts may overlap, a free event may still require travel time, and an apparently affordable set of tickets may exceed the evening's total budget.
You can solve a surprisingly useful part of that problem with a small, privacy-friendly JavaScript planner. It does not need a recommendation API, an account, a tracking pixel, or a database of personal behavior. It accepts a short list of events selected by the visitor and returns a workable itinerary.
This tutorial builds a complete, runnable example with Node.js. It shows where UTC offsets matter, why greedy ranking is not always sufficient, and which real-world details a small algorithm should refuse to guess.
Define a narrow product promise
Instead of claiming to know the "best events in town," the application makes a testable promise: given a small list of candidate activities, find the highest-scoring combination that meets time and spending constraints.
We need five kinds of information:
- A start and end timestamp for each event, with an explicit UTC offset.
- The price per person, represented as a nonnegative integer in a single chosen currency.
- User-selected topics, such as music, live, or games.
- A total budget for the selected events, not merely a maximum ticket price.
- A buffer between events so that consecutive activities do not touch back-to-back. The examples below are fictional. We will not claim that a concert, ticket price, venue, or availability has been verified in the real world.
The planner also deliberately avoids estimating journey times. A configurable buffer is useful for a first pass, but it is not a substitute for route planning or checking a venue's actual entry requirements.
Why timestamps need an offset
JavaScript's Date represents an instant in time internally. However, a string like 2026-11-28T18:00:00 has no stated time zone. Interpreting it on a laptop in one country and a server in another can yield different instants.
Use an explicit offset or Z for UTC:
2026-11-28T18:00:00+03:30
2026-11-28T14:30:00Z
Those strings refer to the same instant. They are not interchangeable with a naive local time string.
There is an additional subtlety: a UTC offset is not a permanent time-zone rule. For recurring events, daylight saving transitions, or future dates whose offsets are not yet known, keep an IANA time-zone identifier (such as Europe/Berlin) with the event's local date and time, and resolve the actual instant using a time-zone-aware library or platform API. Our one-evening demonstration receives already resolved timestamps.
Use an exact search for a small shortlist
Suppose someone has five candidate events and can afford only three. Selecting the first event with the best individual score may block two other compatible events. A simple greedy algorithm can therefore miss a better evening.
For a short, curated shortlist, exhaustive search is straightforward. Each event is either included or excluded, provided that inclusion stays within the budget, maximum number of events, and scheduling buffer. We compare valid selections by total preference score, then use lower cost to break ties.
This is deliberately not a general-purpose scheduler. The running time grows exponentially with the number of candidates. The example sets a limit of 18 eligible events, which is appropriate for a hand-picked evening but not a city's entire event catalog.
Save the following code as event-planner.mjs and run it using node event-planner.mjs.
import assert from "node:assert/strict";
const MINUTE = 60_000;
function instant(value) {
// Require Z or an explicit UTC offset. Bare local times are ambiguous.
if (!/(Z|[+-]\d{2}:\d{2})$/.test(value)) {
throw new Error(Time needs an explicit offset: ${value});
}
const timestamp = Date.parse(value);
if (!Number.isFinite(timestamp)) {
throw new Error(Invalid timestamp: ${value});
}
return timestamp;
}
function normalize(event) {
if (!event.id || !event.title || !Array.isArray(event.tags)) {
throw new Error("Each event needs an id, title, and tags array");
}
if (!Number.isInteger(event.price) || event.price < 0) {
throw new Error(Price must be a nonnegative integer: ${event.id});
}
const startMs = instant(event.start);
const endMs = instant(event.end);
if (endMs <= startMs) {
throw new Error(Event must end after it starts: ${event.id});
}
return { ...event, startMs, endMs };
}
function planEvening(rawEvents, preferences, {
budget = 30,
maxEvents = 3,
bufferMinutes = 15,
} = {}) {
if (budget < 0 || maxEvents < 1 || bufferMinutes < 0) {
throw new Error("Invalid planner limits");
}
const ids = new Set();
const candidates = rawEvents.map(normalize).filter((event) => {
if (ids.has(event.id)) throw new Error(Duplicate id: ${event.id});
ids.add(event.id);
return event.tags.some((tag) => preferences.includes(tag));
}).map((event) => ({
...event,
points: 10 * event.tags.filter((tag) => preferences.includes(tag)).length
+ (event.price === 0 ? 1 : 0),
})).sort((a, b) => a.startMs - b.startMs || a.id.localeCompare(b.id));
// Exhaustive selection is reasonable for a small, user-curated shortlist.
if (candidates.length > 18) {
throw new Error("This demo supports shortlists of at most 18 events");
}
let best = { score: -1, cost: Infinity, chosen: [] };
const chosen = [];
function visit(index, score, cost, lastEndMs) {
if (index === candidates.length) {
if (score > best.score || (score === best.score && cost < best.cost)) {
best = { score, cost, chosen: [...chosen] };
}
return;
}
// Option one: leave this event out.
visit(index + 1, score, cost, lastEndMs);
// Option two: include it, but only if every constraint is met.
const event = candidates[index];
if (chosen.length >= maxEvents || cost + event.price > budget) return;
if (lastEndMs !== null && event.startMs < lastEndMs + bufferMinutes * MINUTE) {
return;
}
chosen.push(event);
visit(index + 1, score + event.points, cost + event.price, event.endMs);
chosen.pop();
}
visit(0, 0, 0, null);
return {
score: best.score,
totalCost: best.cost,
events: best.chosen.map(({ id, title, start, end, price }) =>
({ id, title, start, end, price })),
};
}
// Fictional examples, including prices and times.
const events = [
{ id: "open-mic", title: "Open-mic session", tags: ["music"],
start: "2026-11-28T18:00:00+03:30", end: "2026-11-28T19:00:00+03:30", price: 0 },
{ id: "gallery", title: "Gallery walk", tags: ["art"],
start: "2026-11-28T18:30:00+03:30", end: "2026-11-28T19:30:00+03:30", price: 8 },
{ id: "concert", title: "Independent music concert", tags: ["music", "live"],
start: "2026-11-28T19:30:00+03:30", end: "2026-11-28T21:00:00+03:30", price: 20 },
{ id: "theater", title: "Small-stage performance", tags: ["story"],
start: "2026-11-28T20:15:00+03:30", end: "2026-11-28T22:00:00+03:30", price: 16 },
{ id: "games", title: "Board-game meetup", tags: ["games"],
start: "2026-11-28T21:30:00+03:30", end: "2026-11-28T22:30:00+03:30", price: 7 },
];
const plan = planEvening(events, ["music", "live", "games"], {
budget: 30, maxEvents: 3, bufferMinutes: 15,
});
assert.deepEqual(plan.events.map((event) => event.id),
["open-mic", "concert", "games"]);
assert.equal(plan.totalCost, 27);
assert.throws(() => instant("2026-11-28T18:00:00"), /explicit offset/);
assert.equal(instant("2026-11-28T18:00:00+03:30"),
instant("2026-11-28T14:30:00Z"));
console.log(plan);
The example should select the open-mic session, the concert, and the board-game meetup. The total illustrative cost is 27 units, under the 30-unit budget. Each event starts after the preceding event ends, plus the required 15-minute buffer.
Notice the final assertions. They test the planned sequence, its total cost, rejection of an offset-free timestamp, and equivalence between a timestamp with +03:30 and its UTC representation. Tests like these protect the application from subtle regressions when you later change the interface.
Why this algorithm is explainable
For each eligible event, the model awards ten points for each matching topic. A free event receives a one-point bonus. These choices are simple and visible: you can change the weights without pretending that a mysterious model has understood someone's personality.
The visitor is in control of the preference tags. The application need not infer interests from browsing history, location traces, or unrelated personal data. For a casual event planner, explicit input is often better than invisible profiling.
The algorithm also has a clear rule for ties: if two schedules have the same score, choose the cheaper one. There may still be multiple equally cheap solutions; in that case, the deterministic order of the candidate list determines which is selected. A production application could expose alternative plans instead of hiding that ambiguity.
Add a useful interface without adding surveillance
A small front end could offer filters for event type and a budget slider, followed by a "Build my evening" control. The results should explain why an event was selected and why another was excluded:
- "This activity overlaps your concert."
- "Adding this ticket would exceed the total budget."
- "You requested at least 15 minutes between activities." These explanations can be derived from the same constraints used by the planner. No external analytics service is needed to generate them.
If users want to preserve a plan, keep it in local browser storage or let them export a JSON file. Be clear that browser storage can be cleared and is not a backup. Make sharing opt-in: a shareable itinerary should not expose private notes or account identifiers by accident.
Handle details the algorithm cannot verify
Several important fields should be treated as unknown until confirmed, rather than silently filled in:
Ticket availability. A listed price does not prove that a ticket is still on sale. The application should link to the organizer's verified sales channel or show a last-checked timestamp when one exists.
Accessibility. Do not infer wheelchair access, hearing assistance, or step-free entrances from the event category. Present organizer-provided accessibility details and identify missing information explicitly.
Location and travel. Our 15-minute buffer is a user preference, not an estimate of road conditions or walking time. If the application later adds directions, it must use real venue coordinates and a route service rather than fabricate travel durations.
Currency. The sample uses abstract "units." Real event feeds need explicit currency codes, consistent pricing conventions, and clear handling of fees and taxes. Summing prices from different currencies without conversion is a data-quality bug, not a recommendation feature.
Time changes. An organizer may postpone an event after a user saves a plan. Store the event's source URL and update timestamp so the interface can warn that previously saved information may be stale.
A trustworthy product is often defined more by the guesses it refuses to make than by the number of features it advertises.
Separate discovery from planning
Event discovery and itinerary construction solve different problems. Editorial guides can help readers decide what is interesting; a planner can then help them determine what fits into a real evening. Neither needs to impersonate the other.
For Persian-language readers interested in leisure ideas, music, and concerts, Oghatino is an entertainment-focused editorial destination. The JavaScript example here is an independent teaching exercise; it does not use Oghatino as a live events API or assert that any example event is on sale.
This separation also makes integrations cleaner. A future source adapter can transform verified event data into the normalized records used by planEvening, while the decision engine stays unchanged. Such an adapter should validate timestamps and prices at the boundary and track the source of each claim.
What changes when the catalog grows?
With hundreds or thousands of events, exhaustive subset search is the wrong choice. First filter by date, city, relevant topic, and verified availability. Then consider dynamic programming, mixed-integer optimization, or a documented heuristic, depending on the constraints and performance budget.
The small exact planner still provides value: it becomes a reference implementation for testing faster algorithms. Given the same shortlist and constraints, your optimized version should not return a lower score unless you explicitly accept an approximation tradeoff.
Final takeaway
Building a useful leisure planner is less about predicting taste and more about representing constraints honestly. Explicit time zones prevent silent date errors. Budget and overlap checks make a shortlist actionable. Transparent scoring makes recommendations understandable. A local-first design lets users explore possibilities without handing over a behavioral profile.
Disclosure: This tutorial was drafted with AI assistance. The code was executed and its assertions checked in Node.js. All example events, prices, and schedules are fictional.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.