Skip to main content

This is a library used to make fuzzy date comparisons.

Project description

FlexibleDate

This package can parse potentially dirty date data to create a FlexibleDate object. This package can also compare FlexibleDate objects to give them a score on how close they are to one another. Finally, this package can combine various FlexibleDates for the same event into a FlexibleDate that best represents all date information about that event.

Parsing

The package can parse strings for any day, month, or year information. If any of these attributes are not found, they are set to None.

from FlexibleDate.FlexibleDate import createFlexibleDate, FlexibleDate

fd:FlexibleDate = createFlexibleDate('Do you remember the 21st night of sep?')
print(fd) # None-9-21
print(fd.__repr__()) # FlexibleDate(likelyYear=None, likelyMonth=9, likelyDay=21)

Comparing FlexibleDates

It is often very useful to check how close two dates are, especially given two dates for the same event might be written different, usually because of an accident in remembering day, month, or year. Therefore, it can be useful to check how close the dates are using a scoring system.

Two FlexibleDate objects could potentially be describing the same event, even when they are not identical, especially in the case of birth dates on headstones, as the person who knew it best has no way to correct the relative who is ordering the engraving.

The attributes likelyDay and likelyMonth are compared using the absolute value distance between their respective counterparts in the other FlexibleDate. On the otherhand, the part of the score for likelyYear is based on the difference between the two years, with the score assigned logarithmically staggered based on how far back it is (as records often get less reliable the farther back you go). A positive score is generally a good indicator that the FlexibleDates are not drastically different.

from FlexibleDate.FlexibleDate import compareTwoDates, FlexibleDate

fdA = FlexibleDate(likelyDay=21, likelyMonth=9, likelyYear=1900)
fdB = FlexibleDate(likelyDay=None, likelyMonth=9, likelyYear=1902)

score = compareTwoDates(fdA, fdB)
print(score) # 20.0

Combining FlexibleDates

If there are various (sometimes slightly off) FlexibleDates for a specific event (someone's birth, for example), it can be useful to have a diffinitive FlexibleDate that best represents the event.

from FlexibleDate.FlexibleDate import createFlexibleDate, combineFlexibleDates

fdA = createFlexibleDate('Do you remember the 21st night of sep?')
fdB = createFlexibleDate('22 September 2024')
fdC = createFlexibleDate('21 Octo')

dates = [fdA, fdB, fdC]

fdD = combineFlexibleDates(dates=dates)
print(fdD) # 2024-9-21

Enjoy!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flexibledate-1.0.25.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flexibledate-1.0.25-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file flexibledate-1.0.25.tar.gz.

File metadata

  • Download URL: flexibledate-1.0.25.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flexibledate-1.0.25.tar.gz
Algorithm Hash digest
SHA256 a6403cd518bbe41fe425e6a75dbd1b1626424f6be4e1e6c5605501e4b7766fc6
MD5 5336e563f282435afacc2e4d928b1e06
BLAKE2b-256 dfd1adf87e69ceadd45b25ce35cfe8e7efebd580b9a2b536416b86465a52731d

See more details on using hashes here.

File details

Details for the file flexibledate-1.0.25-py3-none-any.whl.

File metadata

  • Download URL: flexibledate-1.0.25-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flexibledate-1.0.25-py3-none-any.whl
Algorithm Hash digest
SHA256 2563171f2c2d690f2ad4f91e6c061e8f14f3c2e7a652abac8d6b561ec07a5c37
MD5 4d5aa44ca4db23b028f0d0f0fa62f1f5
BLAKE2b-256 8e65228c42d5448b2020301c7851afc09f886f7422708d15419b207ed025c9be

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page