Skip to content

leading zeroes in writing years before 1000 #462

@keesdeschepper

Description

@keesdeschepper

When outputting a date with a year before 1000, there may be a difference in OS in whether there are leading zeroes in the string representation.

library(tidyverse)
as.Date("0020-02-13")
format_csv(tibble(x = as.Date("0020-02-13")))

My Windows

# [1] "0020-02-13"
# [1] "x\n0020-02-13\n"

My Linux

# [1] "20-02-13"
# [1] "x\n20-02-13\n"

I understand that it is hard to account for every OS-specific quirk, but readr itself does not by default guess that "20-02-13" is a date.

Would something like this (probably a Base R variant instead) work?

output_column.Date <- function(x, name){
  str_pad(as.character(x), 10, pad = "0")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviordatetime 📆

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions