---
title: "when: month overflow in a Go date parser | VulCode"
description: "In the when library for Go we fixed month parsing that jumped into the next month when the reference date was the 31st, and added a regression test."
url: "https://vulcode.com/en/opensource/contributions/when"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

olebedev/when

# olebedev/when

A natural language date and time parser in Go with pluggable rules.

[See the repository](https://github.com/olebedev/when) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: Go
- **GitHub stars**: 1,465
- **Merged changes**: 1

## What we changed

Month parsing no longer overflows into the next month when the reference date's day is larger than the target month allows.

### What this work shows

- Date normalisation in Go's time.Date

- Natural language date parsing

- Regression tests with testify

What was broken

### september 5th gave 5 October

With 31 October as the reference date, september 5th gave 5 October and february 11 gave 11 March. Context.Time set the new month with the reference date's day, and time.Date rolled the non-existent 31 September over to 1 October before the parser applied the right day.

How we fixed it

### The day is clamped to the month's length

Before the month changes, the reference day is clamped to the target month's last day by a new daysIn helper. The bare text september now gives 30 September, and the TestExactMonthDateFromLongMonth test parses against 31 October.

[#50](https://github.com/olebedev/when/pull/50)

## Merged change 1

- [#50 Fix month parsing overflowing into the next month Merged 27 September 2026](https://github.com/olebedev/when/pull/50)

## What it taught us

A bug that only shows up on certain days of the month slips past the usual tests. It takes a test with a reference date that reproduces it to catch it.

[More about this technology: Golang](https://vulcode.com/en/technologies/go)

## Other projects we write code for

- [**urfave/cli** Go · 24,329 stars A declarative Go package for building command line tools.](https://vulcode.com/en/opensource/contributions/urfave-cli)

- [**chezmoi** Go · 22,342 stars A dotfiles manager that keeps the same settings on many different machines, securely.](https://vulcode.com/en/opensource/contributions/chezmoi)

- [**goquery** Go · 14,995 stars A Go library for traversing and changing HTML documents in the style of jQuery, built on the golang.org/x/net/html parser.](https://vulcode.com/en/opensource/contributions/goquery)

- [**Ebitengine** Go · 13,647 stars A 2D game engine in Go, used in games released for computers, phones, browsers and consoles.](https://vulcode.com/en/opensource/contributions/ebiten)

- [**Fission** Go · 8,950 stars A serverless functions framework for Kubernetes that runs code as functions and scales them down to zero when they are idle.](https://vulcode.com/en/opensource/contributions/fission)

- [**Concourse** Go · 7,944 stars A container-based automation system written in Go and used mostly for CI/CD. Pipelines and tasks are described in YAML files.](https://vulcode.com/en/opensource/contributions/concourse)

## Describe your project.

A free quote comes back within an hour during working hours.

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
