Project

General

Profile

Actions

Bug #14860

closed

Time.strptime does not work with Julian dates using %j

Added by ajrkerr (Adam Kerr) almost 6 years ago. Updated over 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:87545]

Description

Time.strptime does not appear to be handling Julian dates, it is defaulting the date to be whatever is provided as "now" (e.g. January 1). I believe this is because Time is calling Date._strptime which returns a hash with {:yday=> ...} and does not handle the yday keyword.

Found in 2.3.3, verified not working in 2.5.1.

require "time"
require "date"

### Works for Dates ###
parsed_date = Date.strptime("15300", "%y%j")
expected_date = Date.new(2015, 10, 27)
# Does not raise
raise "dates not equal" if expected_date != parsed_date


### Does not work for Time ###
parsed_time = Time.strptime("15300", "%y%j")
expected_time = Time.new(2015, 10, 27)
# Raises
raise "times not equal" if expected_time != parsed_time

Related issues 2 (0 open2 closed)

Related to Ruby master - Bug #15776: Difference between Time.parse behaviour between 2.6.0 and 2.6.1+Rejectednobu (Nobuyoshi Nakada)Actions
Has duplicate Ruby master - Bug #14933: Time.strptime with ordinal datesClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0