Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fuzzy date/time management library for .NET

I am searching for a .NET library that can store and manage fuzzy (i.e. uncertain) dates/times, that is, temporal expressions that do not follow the usual precise pattern of day, month, year, hour, minute, second. I need something that can handle date/time values expressed, for example, as:

  • Second quarter of 1985
  • Early 1930s
  • Second third of the XVII century

The library would probably implement a FuzzyDateTime type or something like that, and allow multiple ways to construct instances of it from text and/or regular DateTime values. Comparison and sorting features are also required.

So, my question is: do you know of any available products that fit this description? I am happy to consider all sorts of products, i.e. commercial, open source, freeware, etc.

Any ideas? Many thanks.

like image 711
CesarGon Avatar asked Aug 03 '11 13:08

CesarGon


1 Answers

You'll likely have to code this from scratch. There may be a Java library that you could convert, but it seems this type of functionality is a thing of academia right now, rather than something being in production various places. In the end you may be able to use something academic, but you'll probably have to code your own based on your need.

To allow greatest flexibility, I would store each part of the date in separate nullable fields, with a value indicating the uncertainty of the first null field.

class UncertainDate
{
    public byte? Millennium { get; set; }
    public byte? Century { get; set; }
    public byte? Decade { get; set; }
    public byte? Year { get; set; }
    public byte? Month { get; set; }
    public byte? Day { get; set; }
    // more as you see fit

    public decimal Uncertainty { get; set; }
}

As an example, "first quarter of 2000" would be represented as:

var d = new UncertainDate() { Millennium = 2, Century = 0, Decade = 0, Year = 0, Uncertainty = 0.25m };

That leaves you a long route to travel as far as parsing string input and giving string output, but it makes comparisons easy (compare each field in order, first or lowest uncertainty loses).

You could also use an enumeration for the uncertainty, maybe values like FirstQuarter, FirstHalf, Early, Late, ThirdQuarter, etc. Decimal makes relative comparisons easy, but harder to back convert to things like "second half" (i.e. would 0.75 be "second half" or "third quarter" ?)

For reference, there have been similar questions asked.

like image 128
drharris Avatar answered Sep 30 '22 10:09

drharris