Skip to content

time: Parse too greedy when parsing some formats #12919

@ksshannon

Description

@ksshannon
  1. What version of Go are you using (go version)?

    $ go version go version devel +2d823fd Tue Oct 13 01:04:42 2015 +0000 linux/amd64

  2. What operating system and processor architecture are you using?

    linux/amd64

  3. What did you do?

    Attempted to parse this time: "618 AM MDT TUE OCT 13 2015" with this format string: "304 PM MST Mon Jan 02 2006"

  4. What did you expect to see?

    No parsing error, and a time.Time representing that moment.

  5. What did you see instead?

    The parsing fails, and the error reported: parsing time "618 AM MDT TUE OCT 13 2015": hour out of range. The hour is interpreted as 61.

    The format works properly with a two digit hour. It seems getnum() in time/format.go takes up to two characters whenever the second character is valid which leads to the issue.

  6. Playground example with examples that fail and pass for the given format:

    http://play.golang.org/p/mZ-m7gJlvy

Apologies if my code is messy...

The format is used as a time/version stamp for the US National Weather Service in their forecast discussion products, for a real world example, http://www.wrh.noaa.gov/total_forecast/getprod.php?wfo=boi&pil=AFD&sid=BOI&version=1

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions