Coder Social home page Coder Social logo

Feature requests: more flexibly find date substring in a non-date string; and process additional incomplete date substrings about anytime HOT 11 CLOSED

chrisumphlett avatar chrisumphlett commented on May 27, 2024
Feature requests: more flexibly find date substring in a non-date string; and process additional incomplete date substrings

from anytime.

Comments (11)

eddelbuettel avatar eddelbuettel commented on May 27, 2024

It's tricky. I think the 'leading stuff' maybe be best handled by an added 'filter' you could add:

R> anydate(gsub("(^[a-z ]*)", "", "asfdsfsdf 2020-01-01"))
[1] "2020-01-01"
R>

The second one is a no-no as our parsers aim to create proper date or datetime objects. And a pair on month and year is simply not a date. So there too you may have to build something on top of what we offer.

from anytime.

chrisumphlett avatar chrisumphlett commented on May 27, 2024

Thanks. The regex is a simple workaround for that one scenario. It doesn't help in two sub-cases I have:

  1. Leading numbers in the string before the date
  2. Date sub-strings with a format like "May 20, 2020".

As far as the need for proper objects, admittedly I'm far from an expert on how the parsers work. My suggestion is not that you only have a month and year, but that you have a simple set of rules to impute missing parameters (day =1, month/year = current month/year).

from anytime.

eddelbuettel avatar eddelbuettel commented on May 27, 2024

The package makes no claim to help with any possible date formats. Some remain too irregular. There is no way around this.

It does offer you ways to accomodate the need for special treatment, see help(addFormats).

I still think we should close this.

from anytime.

chrisumphlett avatar chrisumphlett commented on May 27, 2024

thanks

from anytime.

eddelbuettel avatar eddelbuettel commented on May 27, 2024

BTW your last example already works:

R> anytime::anydate("May 20, 2020")
[1] "2020-05-20"
R> 

from anytime.

chrisumphlett avatar chrisumphlett commented on May 27, 2024

That one works, with no leading text. This doesn't work:

anydate(gsub("(^[a-z ]*)", "", "asfdsfsdf May 20, 2020"))

from anytime.

eddelbuettel avatar eddelbuettel commented on May 27, 2024

Regular expressions are very powerful. It pays off to read up a little. Here [a-z] means letters; use [a-z0-9] and you may need to add punctuation etc -- this is no longer an anytime issue.

Best of luck, and I hope you continue to find anytime useful, even with challenging data.

from anytime.

chrisumphlett avatar chrisumphlett commented on May 27, 2024

addFormats is promising for me. Thank you for sharing that. Is the addition of a format permanent, just for the session, something else?

anytime::anydate("May 2020")
[1] NA
anytime::addFormats("%b %Y")
anytime::anydate("May 2020")
[1] "2020-05-01"

from anytime.

eddelbuettel avatar eddelbuettel commented on May 27, 2024

Just for the session. But nothing is stopping you from adding library(anytime); addFormats(c("....". "...")) to your R startup. Or maybe to the scripts or functions you use for this project.

from anytime.

chrisumphlett avatar chrisumphlett commented on May 27, 2024

Same logic also for date times. anytime doesn't like HH:MM with no :SS. getFormats always has %H:%M:%S. And then anytime also doesn't like am/pm either...? I don't see that in any of the formats. I'm opening a separate thread about time zones.

from anytime.

chrisumphlett avatar chrisumphlett commented on May 27, 2024

Just for the session. But nothing is stopping you from adding library(anytime); addFormats(c("....". "...")) to your R startup. Or maybe to the scripts or functions you use for this project.

Yep understood, just making sure I knew if it was necessary. I'd probably to it on a project/process-level. I use anytime in almost every project and I've never needed to alter the formats.

from anytime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.