scrapinghub / scrapinghub/dateparser

QUESTION: parameter or method to print the code format of the date

Open
#1,030 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.9k
Forks
520
Avg merge
22h 56m
Merged PRs (30d)
6

Description

Is there a parameter or method to print the code format string that matches the parsed date?
For example, in the following code:

from datetime import datetime
now = datetime.now()
date_time = now.strftime("%m/%d/%Y, %H:%M:%S")
print("date and time:",date_time)

You will get:

date and time: 12/21/2021, 22:08:06

So with this code:

dateparser.parse(date_time)

You will get:

datetime.datetime(2021, 12, 21, 22, 08, 06)

Is there a way to run something like this?:

dateparser.get_date_pattern(date_time)

And as a result:

"%m/%d/%Y, %H:%M:%S"

I saw a similar question in Stack Overflow: https://stackoverflow.com/q/33986096/6315428

The purpose? Generate synthetic data for privacy protection, looking to express dates in the same original format, replacing the value with a different one.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing dateparser.parse behavior and the datetime.strftime example in the issue. Determine whether the parsed input preserves enough information to recover the original format string, and define what dateparser.get_date_pattern(date_time) should return for the shown example. Done means the behavior and supported cases are documented and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.