7

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.

CesarGon
  • 15,099
  • 6
  • 57
  • 85
  • Ideas for what? Implementing this? Where one exists? What is your question? – Oded Aug 03 '11 at 13:32
  • 3
    In terms of traditional "fuzzy" logic, I'm not sure I'd call those fuzzy; well, maybe "Early 1930s" is vague, but the others are precise - but expressed in non-standard ways – Marc Gravell Aug 03 '11 at 13:32
  • @Oded: my question is stated in the first paragraph of the question: "I am searching for a .NET library that...". Maybe it is not too clear that I am trying to find a product to buy and/or use rather than advice on how to develop it from scratch; I am editing now to clarify. – CesarGon Aug 03 '11 at 18:23
  • @Marc Gravell: I am not really interested in fuzzy logic as usually understood by academia (i.e. Zadeh and related). From what I've been looking at, a linguistic approach such as that of Lakoff's radial categories should work better, since uncertainty in the temporal realm is most often epistemic rather than ontic. Sorry for the geekout, but your remark touched a hot research issue indeed. :-) – CesarGon Aug 03 '11 at 18:30
  • It seems like you could simply create a series of extension methods on a `DateTime` to do this for you. This way, comparisons and other operators are built-in, and it separates the storage from the display logic. I'm not aware of any existing libraries that go to this extreme (most follow the "5 weeks ago" routine). But it seems trivial enough to code it up yourself based on what your actual needs are. – drharris Aug 03 '11 at 19:07
  • @drharris: Thanks for your proposal, but I don't think that's what I need. :-) I am looking for something that is radically different to the `DateTime` type in .NET. Storing, comparing, sorting and displaying uncertain (or "fuzzy") time values is something that needs more than a bunch of extension methods. If you think otherwise, please flesh out your proposal as an answer and I'll be happy to consider it. Thank you. – CesarGon Aug 03 '11 at 19:26
  • Ah, my bad. I thought you meant that you would store an accurate date and time and simply display it in a fuzzy way. Actually storing an uncertain date is a whole different matter. Good luck! – drharris Aug 03 '11 at 19:32

2 Answers2

7

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.

Community
  • 1
  • 1
drharris
  • 11,194
  • 5
  • 43
  • 56
  • Thanks. I am looking for an existing product, not to develop something from scratch. And many thanks for the link to the related question; most interesting! – CesarGon Aug 04 '11 at 13:06
3

I don't know of any library/product although I can imagine that this point has been at least thought about in any of the "semantic" fields (like semantic web etc.).

IF I undestand corectly what you are after (esp. when you want to sort etc.) then those "fuzzy" things are just "intervals" between two specific points in time...

You could create a class containing 2 DateTimes... Start and End... alternatively a Start plus duration...
Add to that whatever representation you might imagine... Some constructors to interpret what you want to throw at them (like something that "knows" what "early" or "quarter" means) and builds the relevant start and end from that.

Since you have a start DateTime and an end (either DateTime or a duration) these are perfectly comparable and sortable...

As for storing you could make it serializable...

Yahia
  • 69,653
  • 9
  • 115
  • 144