Skip to content

Add helpers to decode DOS-packed date/time fields on Fat12Entry #2

@AlbatrossMicrosystems

Description

@AlbatrossMicrosystems

Summary

Fat12Entry exposes three raw DOS-packed integer fields — createdDate,
modifiedDate, and modifiedTime — straight from the on-disk directory entry.
Callers currently have to know the FAT bit-packing to make sense of them. Add
pure helper functions that decode these packed values into java.time
types.

Why this is a good first issue

  • Pure functions, no I/O — no device, no rollback path, no golden images.
  • The encoding is fully specified by the FAT spec, so behaviour is unambiguous.
  • Excellent, well-bounded test surface (exact bit patterns → exact dates/times).

Background — the FAT date/time packing

Date (16-bit, applies to createdDate / modifiedDate):

  • bits 0–4: day of month (1–31)
  • bits 5–8: month (1–12)
  • bits 9–15: year offset from 1980

Time (16-bit, applies to modifiedTime):

  • bits 0–4: seconds / 2 (0–29 → 0–58s)
  • bits 5–10: minutes (0–59)
  • bits 11–15: hours (0–23)

Proposed change

Add pure decode helpers (free functions or an extension/companion on Fat12Entry),
e.g.:

/** Decode a FAT-packed 16-bit date field into a LocalDate (null if the field is 0). */
fun decodeFatDate(packed: Int): LocalDate?

/** Decode a FAT-packed 16-bit time field into a LocalTime (2-second resolution). */
fun decodeFatTime(packed: Int): LocalTime

Convenience accessors on the entry are welcome too (e.g.
Fat12Entry.modifiedDateTime(): LocalDateTime?), as long as the underlying
raw Int fields stay as-is for backward compatibility.

Acceptance criteria

  • decodeFatDate / decodeFatTime (or equivalent) added and public.
  • Raw Int fields on Fat12Entry are unchanged (additive only).
  • Unit tests with hand-computed fixtures, e.g. 2026-06-18 and a known time, plus edge cases: 0 date, day/month = 1, year 1980 (offset 0), seconds rounding (odd seconds truncate to even).
  • KDoc cites the bit layout above.
  • ./gradlew :core:test passes.

Pointers

  • core/src/main/kotlin/com/ams/fat12ex/core/Fat12Entry.kt — the three raw fields.
  • Listing entries to test against: Fat12Volume.list("/") returns List<Fat12Entry>.
  • Mirror an existing pure-logic test style from core/src/test/kotlin/com/ams/fat12ex/core/.

How to get started

git clone https://github.com/AlbatrossMicrosystems/fat12-engine.git
cd fat12-engine
./gradlew :core:test

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions