473,795 Members | 2,840 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Handling freeform date field order


For an all-numeric Gregorian date to be intrinsically unambiguous, it
must generally be of the form /\d{3,}\D+\d+\D+ \d+/ ; and we've
discussed handling that.

But if the month is given in letters (in full, as a LTA, or as Roman
numerals) [and the language is known], then the date is unambiguous[*]
if the value of the year field is greater than the greatest possible day
field value - in which case the year value is greater than the actual
day value - whatever order the fields are in (even "Mar 2006 15" can
only have one meaning, likewise "27 Feb 29").

ISTM that the function will in all cases above put the fields into an
array in Reverse-American order (Y D M), which is good enough for
subsequent processing (it also strips day suffix as in 9th) :-
function SFr, b) { return (parseInt(b,10) |0) - (parseInt(a,10) |0) }

function (X) { return X.split(/\W+/).sort(SF) }
Comment? I can't think of an elegant modification to get Y M D order.

I doubt whether ECMA's reading this; but efficient array primitives to
rotate an array in either direction and to transpose a pair (adjacent or
any) of elements might be appreciated.
[*] apart from guess-the-century error.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Mar 15 '06 #1
3 1392
JRS: In article <Qz************ **@merlyn.demon .co.uk>, dated Wed, 15
Mar 2006 23:35:56 remote, seen in news:comp.lang. javascript, Dr John
Stockton <jr*@merlyn.dem on.co.uk> posted :

function SFr, b) { return (parseInt(b,10) |0) - (parseInt(a,10) |0) }

function (X) { return X.split(/\W+/).sort(SF) }


Non-reproducible copy'n'paste error; first should be

function SF(a, b) { return (parseInt(b,10) |0) - (parseInt(a,10) |0) }

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.
For news:borland.*, use their server newsgroups.borl and.com ; but first read
Guidelines <URL:http://www.borland.com/newsgroups/guide.html> ff. with care.
Mar 16 '06 #2
Dr John Stockton wrote:
[...] "Mar 2006 15" can only have one meaning,
True.
likewise "27 Feb 29").
Well, is it February 27, (19|20)29, or February 29, (19|20)27?
ISTM that the function will in all cases above put the fields into an
array in Reverse-American order (Y D M), which is good enough for
subsequent processing (it also strips day suffix as in 9th) :-
function SFr, b) { return (parseInt(b,10) |0) - (parseInt(a,10) |0) }

function (X) { return X.split(/\W+/).sort(SF) }
Comment? I can't think of an elegant modification to get Y M D order.
You could parse for known month names (and abbreviations) with
RegExp.prototyp e.exec() and then change the order of matched
substrings. However, if the year is allowed to be expressed
with numeric values smaller than 32, the date-year ambiguity
remains.
I doubt whether ECMA's reading this; but efficient array primitives to
rotate an array in either direction and to transpose a pair (adjacent or
any) of elements might be appreciated.


Array.prototype .rotate = function(positi on)
{
if (position > 0)
{
// rotate right
return [this.pop()].concat(this);
}
else if (position < 0)
{
return this.concat(thi s.shift());
}

return this;
};

Array.prototype .exchange = function(i, j)
{
// rotate right
var tmp = this[j];
this[j] = this[i];
this[i] = tmp;
return this;
};

alert([1, 2, 3].rotate(-1))
alert([1, 2, 3].exchange(0, 2))

Did I miss something?
PointedEars
Mar 17 '06 #3
JRS: In article <19************ *****@PointedEa rs.de>, dated Fri, 17 Mar
2006 21:56:08 remote, seen in news:comp.lang. javascript, Thomas
'PointedEars' Lahn <Po*********@we b.de> posted :
Dr John Stockton wrote:
[...] "Mar 2006 15" can only have one meaning,
True.
likewise "27 Feb 29").


Well, is it February 27, (19|20)29, or February 29, (19|20)27?


A) You cut my note "apart from guess-the-century error".
B) February only has 29 days in years divisible by four[*].

ISTM that the function will in all cases above put the fields into an
array in Reverse-American order (Y D M), which is good enough for
subsequent processing (it also strips day suffix as in 9th) :-
function SFr, b) { return (parseInt(b,10) |0) - (parseInt(a,10) |0) }

function (X) { return X.split(/\W+/).sort(SF) }
Comment? I can't think of an elegant modification to get Y M D order.


You could parse for known month names (and abbreviations) with
RegExp.prototy pe.exec() and then change the order of matched
substrings.


Not elegant.

If we require the year number to be greater than 32, 32 could be
subtracted from the result of each parseInt(). Sorting would then put
the month in the middle. But that's not really elegant.

However, if the year is allowed to be expressed
with numeric values smaller than 32, the date-year ambiguity
remains.
That's why I put "if the value of the year field is greater than the
greatest possible day field value".

I doubt whether ECMA's reading this; but efficient array primitives to
rotate an array in either direction and to transpose a pair (adjacent or
any) of elements might be appreciated.

...


Those were not primitives.
[*] and, nowadays, not all of those.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Mar 18 '06 #4

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

Similar topics

4
2824
by: John Fereira | last post by:
So, one of the limitations of multipart-form handling is that when an <input type="file" ..> tag is used it will bring up a window which allows a user to select a file for upload but won't allow the user to select multiple files. As you may know, the tag produces a text input field with an adjacent button for selecting a file from the local file system. As I would like to be able to allow the user to upload an arbitrary number of files...
8
4098
by: Jeremy | last post by:
We have some date fields in our HTML forms in various places. In the accounts package we use, there is some pretty nifty date handling. It has a standardised date format of dd/mm/yyyy and if you enter e.g. 3-12 it will switch it to 3/12/2005 Same applies for e.g. 3:12 etc Anyone know of some javascript which will do this for our HTML form
6
4441
by: yoshitha | last post by:
hi db : sql server 2000 lan : C#.net(ASp.Net) in my database table there are 2 fileds of data type datatime. in field 1 i'm storing date in field 2 i'm storing time.
5
2639
by: AAJ | last post by:
Hi Does anyone know of any good publically available set of standards for managing dates when dealing with a database server (in my case SQL Server 2000 and c# VS2005). At the moment, if I create a record in the database for say a job, the invoicedOn date field will be left null within the data base, not being assigned untill its actually invoiced.
2
1773
by: Kevin Frey | last post by:
One of my chief criticisms of validators in an ASP.NET page is that they can result in a developer re-implementing much of the "business logic" of a transaction at the page level. Assuming we have an object that implements business logic, and that object is utilised via an ObjectDataSource, I wish to enquire what the correct method is for handling errors from the business logic object. For example, there are some circumstances where a...
7
1982
by: Ron | last post by:
Hi All (yet again today...) Input clerk gets to "date of order" control on order form and is supposed to enter the date of the order. I've got that defaulting to today's date, which sounds logical...except that sometimes orders are made on Friday, but not entered until the following Tuesday, or whatever. Of course, it's a standard control, so the default date can be replaced by typing another data with month, day, year, etc. For the...
8
13745
vs2k8
by: vs2k8 | last post by:
Hello guys, New to this forum and new to access programing, my issue is I am comparing 2 date fields, I have to validate that Order Rcvd Dt should be less then Ord Comp date and Order Comp date cannot be null. So I written a function to validate the field which is shown below, If I write before update on Order_comp_date field then I get run time error message : You must save the field before you execute setfocus method Private Sub...
4
1784
by: DHS1 | last post by:
Hey guys. I have a lab that is due in two weeks, but I wanted to start on it now. Problem is, I'm at home during christmas break so I can't ask my professors. Here's my problem: I am given a very fragile program and I have to add the exception handling and error checking and pretty much make it uncrashable. I will show just one small step in this lab. If you can answer it, I think I'll be able to do the rest. I just need to get headed in...
2
3675
7 of 9
by: 7 of 9 | last post by:
OK here is my code: Select Case DateDiff("D", Shipdt, Date) Case Is > 90 WTAge = "GT-90" Case Is > 60 WTAge = "61-90" Case Is > 30
0
9522
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10217
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10167
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9046
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7544
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2922
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.