DEV Community

Cover image for Two things called "Julian date", and a holiday that falls in the wrong year
yoyoma23
yoyoma23

Posted on

Two things called "Julian date", and a holiday that falls in the wrong year

I run TimeCalc, a small independent site with free date and time calculators. Two of them were more interesting to build than I expected, so here's a short write-up.

1. "Julian date" means two different things

→ Julian Date Converter

  • On food packaging, in military logistics and on mainframes it's an ordinal date: year + day of the year, written YYDDD. 26307 is day 307 of 2026, i.e. November 3, 2026.
  • In astronomy it's the Julian Day Number: a running count of days since noon on January 1, 4713 BC. January 1, 2000 is 2451545.

People searching for one often get the other, so the page shows both: YYDDD, YYYYDDD and the Julian Day Number. It converts in both directions: type 26307 or pick a date.

If you already count days since the Unix epoch, the Julian Day Number takes one addition:

type Ymd = { y: number; m: number; d: number };

// Days since 1970-01-01 (UTC) for a calendar date
const dayNumber = ({ y, m, d }: Ymd) => {
  const t = new Date(0);
  t.setUTCFullYear(y, m - 1, d); // not Date.UTC: Date.UTC(99, 0, 1) is 1999
  return Math.round(t.getTime() / 86_400_000);
};

const julianDayNumber = (date: Ymd) => dayNumber(date) + 2_440_588;

julianDayNumber({ y: 2000, m: 1, d: 1 }); // 2451545
Enter fullscreen mode Exit fullscreen mode

The catch with YYDDD is leap years. Every day after February 28 moves by one, so 061 is March 2 in 2026 but March 1 in 2028.

2. Business days, and a holiday in the previous year

→ Business Days Calculator

It counts business days between two dates, or adds N business days to a date. It skips weekends and the 11 US federal holidays and lists which holidays it skipped.

Two decisions I had to make:

Which end counts? By default the start date is excluded and the end date included, because that's how "ships in 5 business days" is usually read. Excel's NETWORKDAYS counts both ends, so there's a checkbox to match it.

Observed dates. A holiday on a Saturday is observed on the Friday before, and one on a Sunday on the Monday after. Independence Day 2026 is a Saturday, so it's observed on Friday, July 3.

Observed dates lead to the edge case I like most: New Year's Day 2028 is a Saturday, so it's observed on Friday, December 31, 2027. It's a 2028 holiday that falls in 2027. If you only generate holidays for the years in your range, you miss it. So I generate one extra year on each side:

const holidaySet = (fromYear: number, toYear: number) => {
  const set = new Map<number, string>();
  for (let y = fromYear - 1; y <= toYear + 1; y++)
    usFederalHolidays(y).forEach((h) => set.set(h.day, h.name));
  return set;
};
Enter fullscreen mode Exit fullscreen mode

That's why 2027 has 249 business days and 2026 has 250.

Stack

Static Astro pages, with each tool written as a custom element in plain TypeScript and no UI framework. Everything is calculated in the browser. There are no accounts and no ads. The date math and holiday rules have unit tests (node --test).

Feedback welcome

  • Which edge cases did I miss?
  • Would holidays for other countries be useful to you?
  • Have you seen other "Julian date" formats in the wild?

Top comments (6)

Collapse
 
userxnom profile image
Abdullah Naseer •

The observed-holiday case is the one I would steal — a 2028 holiday falling in 2027 is exactly the kind of silent off-by-one that breaks a date range without any error. And yes, holidays for other countries would be useful to me: my date logic is only as good as the calendar it is tested against, and a US-only list would quietly miss the days that matter here.

Collapse
 
yoyoma23 profile image
yoyoma23 • • Edited

Glad that edge case was useful! It caught me off guard too — nothing throws, you just quietly get 250 instead of 249.

Your comment nudged me to stop putting off multi-country support, so I just shipped a country selector on the Business Days Calculator with UK (England & Wales), Canada, Australia, Germany, and Poland — including substitute-day rules (like UK Christmas/Boxing Day weekend shifts) and Easter-based movable holidays.

If your country isn't in that list yet, let me know which one you'd need and I'll add it next!

Collapse
 
userxnom profile image
Abdullah Naseer •

Pakistan, please — I'm based here, so that would be the one I'd actually use day to day. The substitute-day handling you mentioned is exactly the tricky part here too, especially around Eid, when the date depends on moon sighting and can shift at short notice.

How are you planning to handle lunar holidays like that, where the date isn't fixed far in advance? Would you hard-code an expected date and update it, or treat those as approximate until they're confirmed?

Thread Thread
 
yoyoma23 profile image
yoyoma23 •

That's the exact split between algorithmic calendars and observed ones. Easter can be computed centuries ahead with no ambiguity, whereas moon-sighted holidays like Eid-ul-Fitr, Eid-ul-Azha, and Ashura can't — any pure formula is only an estimate and can be off by a day.

So I went with a hybrid model and just pushed Pakistan live (alongside India, UAE, and Singapore):
→ Pakistan Working Days Calculator

  • Fixed national holidays (Kashmir Day, Pakistan Day, Labour Day, Youm-e-Takbeer, Independence Day, Iqbal Day, Quaid-e-Azam Day) are computed by rule.
  • Lunar holidays live in an explicit per-year table (Cabinet Division gazette dates for 2026, projected astronomical dates for 2027) and are explicitly labeled "subject to moon sighting" in the holiday table and "(est.)" in the skipped-holidays readout until confirmed.
  • Overlapping holidays on the same weekday (like Pakistan Day + Eid-ul-Fitr Day 3 on March 23, 2026) merge their names and are skipped once.

Let me know if anything looks off for local use — happy to tweak it!

Thread Thread
 
userxnom profile image
Abdullah Naseer •

Thank you for building this out so quickly — the Pakistan list looks right to me from local use: Kashmir Day, Pakistan Day, Labour Day, Youm-e-Takbeer, Independence Day, Iqbal Day, and Quaid-e-Azam Day are exactly the fixed ones I'd expect, and the hybrid model is the right call. A pure formula can never settle Eid, since the date only becomes certain once the moon sighting is announced, so keeping the lunar dates in an explicit per-year table and marking them "(est.)" until confirmed is the honest way to do it. Merging the March 23, 2026 overlap instead of double-counting it is a nice touch too — that's the kind of edge case that quietly breaks a working-days count. One thing I'd check: does your skipped-holidays readout also show the merged name, so someone can see why that day was skipped? And how are you planning to update the table when the gazette or moon-sighting announcement confirms a lunar date — a manual edit each year, or a source you can pull from?

Thread Thread
 
yoyoma23 profile image
yoyoma23 •

Thanks for double-checking the list!

1. Merged name in the UI: Yes — holidaySet combines overlapping names on the same day key, and businessDaysBetween passes that string straight into the "Holidays skipped" readout. So a range covering March 23, 2026 shows Pakistan Day / Eid-ul-Fitr (Day 3) (March 23, 2026) and counts it as a single skipped weekday.

2. Updating confirmed lunar dates: For now, a small manual edit when the Cabinet Division / Ruet-e-Hilal announcement drops — adjust the day if it shifted by ±1, flip the tentative flag off, and push (CI runs the tests and deploys the static build automatically). I looked at pulling from third-party holiday APIs, but most of them either lag behind last-minute moon sightings or return Hijri estimates without marking them as unconfirmed, which brings back the exact silent-error problem. For a handful of lunar dates a year, checking the official notification and making a 3-line commit feels safer than trusting an unverified upstream feed.