473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

user friendly datetime features

Many times a more user friendly date format is convenient than the
pure date and time.
For example for a date that is yesterday I would like to see
"yesterday" instead of the date itself. And for a date that was 2 days
ago I would like to see "2 days ago" but for something that was 4 days
ago I would like to see the actual date. This is often seen in web
applications, I'm sure you all know what I'm talking about.

I'm guessing this feature is needed so often in so many projects that
it has been implemented already by several people. Does anyone know of
such a stand alone module?
Jan 9 '08 #1
7 2380
"Daniel Fetchinson" <fe********@googlemail.comwrites:
I'm guessing this feature is needed so often in so many projects that
it has been implemented already by several people. Does anyone know of
such a stand alone module?
The 'python-dateutil' library allows easy *programmatic* manipulation
of relative date expressions, but not in natural language.

The closest I know of is the "Chandler Desktop" release notes
<URL:http://chandlerproject.org/Projects/ReleaseNotesmentioning
"parsing of natural language date and time". You might want to get the
source code and see if their implementation is suitable for your use.
Do be sure to check the license terms for compatibility with your own
intended use of the work.

--
\ "Intellectual property is to the 21st century what the slave |
`\ trade was to the 16th." -- David Mertz |
_o__) |
Ben Finney
Jan 9 '08 #2
or just calculate the difference between the moment you are and the
date before and display the result in a cases (if diff is one day or 2
days or ...)
Jan 9 '08 #3
On Jan 8, 7:57*pm, Ben Finney <bignose+hates-s...@benfinney.id.au>
wrote:
"Daniel Fetchinson" <fetchin...@googlemail.comwrites:
I'm guessing this feature is needed so often in so many projects that
it has been implemented already by several people. Does anyone know of
such a stand alone module?

The 'python-dateutil' library allows easy *programmatic* manipulation
of relative date expressions, but not in natural language.
I think the OP was looking for presentation of dates in a friendly
format, not parsing, but it so happens that I started such a parser
with pyparsing about a month ago, and was about 1/2 finished with it
when I saw your post. I dredged up the code from where it was, and
have a semi-working version now.

NLTK is not needed, as you can constrain and structure the vocabulary
surprisingly well. Probably trickier is to establish your own
conventions for the meanings of "now", "today", etc. (For instance, I
interpret "today" as "the current date, at time 00:00:00".) "A day
from now" is "the current time, with tomorrow's date". "In a day"
could go either way - interpret like "tomorrow" or like "a day from
now." But once these are settled, a reasonable grammar can be
composed.

My first version is fairly brute force and hackish, but I've gotten
some insights into the date arithmetic, and which words behave much
like operators. Of course, this is all driven around English and
English idioms - converting to another language would probably be
starting from scratch.

Here are the tests for this first version (these tests all pass):
today
tomorrow
yesterday
in a couple of days
a couple of days from now
a couple of days from today
in a day
3 days ago
3 days from now
a day ago
now
10 minutes ago
10 minutes from now
in 10 minutes
in a minute
in a couple of minutes
20 seconds ago
in 30 seconds
20 seconds before noon
20 seconds before noon tomorrow
noon
midnight
noon tomorrow

You can see the results and the parser code at:
http://pyparsing.wikispaces.com/UnderDevelopment.

-- Paul
Jan 9 '08 #4

For PARSING see http://code-bear.com/code/parsedatetime/

The OP was looking for presentation though. I know roundup has code for this
if an independent library can't be found.

Eddie
Jan 9 '08 #5
For PARSING see http://code-bear.com/code/parsedatetime/
>
The OP was looking for presentation though. I know roundup has code for
this if an independent library can't be found.

Thanks for all the responses!
Indeed I was looking for presentation and not parsing, I'll take a
look at roundup.

Cheers,
Daniel
Jan 9 '08 #6
"Daniel Fetchinson" <fe********@googlemail.comwrites:
The OP was looking for presentation though. I know roundup has
code for this if an independent library can't be found.

Thanks for all the responses!
Indeed I was looking for presentation and not parsing, I'll take a
look at roundup.
Yes, that's why I indicated that Chandler Desktop would be a good
place to look. Roundup sounds like an equally good place to look.
Hopefully, with a couple of options like that, you'll find something
decent.

It would be good to see a generic "natural-language datetime
presentation" library in the Cheeseshop, since the functionality seems
quite well-suited to a separate generic library.

--
\ "The best mind-altering drug is truth." -- Jane Wagner, via |
`\ Lily Tomlin |
_o__) |
Ben Finney
Jan 9 '08 #7
The OP was looking for presentation though. I know roundup has
code for this if an independent library can't be found.
Thanks for all the responses!
Indeed I was looking for presentation and not parsing, I'll take a
look at roundup.

Yes, that's why I indicated that Chandler Desktop would be a good
place to look.
I see, I thought that would only be a good place to look for parsing.
Now I downloaded Chandler and quickly found the parsing module they
use but not the one for display but it has to be there I'm sure. They
must use this all over the place.
Roundup sounds like an equally good place to look.
Yes, roundup has a separate module for this and it does the display,
not parsing. This is exactly what I need.
Hopefully, with a couple of options like that, you'll find something
decent.
Yep, I already did :)
It would be good to see a generic "natural-language datetime
presentation" library in the Cheeseshop, since the functionality seems
quite well-suited to a separate generic library.
Exactly, that's what I was mentioning in my original post too.
Actually it looks like the one included in roundup is a stand alone
library for display (but not parsing). It's released under the same
license as python itself maybe they can be convinced to release it as
a stand alone module to the cheeseshop.

Cheers,
Daniel
Jan 10 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: Steven O. | last post by:
I am seeking some kind of tool that I can use for GUI prototyping. I know how to use Visual Basic, but since a lot of software is being coded in Java or C++, I'd like to learn a Java or C++ -based...
0
by: Nemo | last post by:
I have problem to get my dates from my user control. The problems is that the datetimes sets after when I get the values from my aspx page. Here is how my user control lock likes. private...
7
by: Jose Cuthberto | last post by:
WRAPPER CODE FOR A SET OF HTML FILES, AND BUTTON BAR LOOKS LIKE BELOW: |< < <> > >| => <= O' (magnifying glass for small gif text) I have a number of isolated html files for a 1000 page...
88
by: Mike | last post by:
Is there a way to determine what a user's default email client is? I read a post from 3 years ago that said no. I guess I'm hoping something has come along since then.
11
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why...
24
by: Rob R. Ainscough | last post by:
VS 2005 I have: ClickOnce deployment User's that hate and or don't want to use an IE Client (don't blame them) I don't see how ASPX web pages are going to survive? With .NET 2.0 and clickonce...
1
by: Jonathan Wood | last post by:
Okay, as evidenced by other questions, I am an experienced programmer very new to ASP.NET. I have a vertical navigation bar. It is all one color with several panels inside it with a different...
95
by: hstagni | last post by:
Where can I find a library to created text-based windows applications? Im looking for a library that can make windows and buttons inside console.. Many old apps were make like this, i guess ...
6
by: ajk | last post by:
Hi I was wondering how to show different properties in design and run-mode for a user control? Is it possible to do this when implementing the System.ComponentModel.ICustomTypeDescriptor...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.