[Info-vax] date comparison format from a program
Stephen Hoffman
seaohveh at hoffmanlabs.invalid
Mon May 20 18:03:07 EDT 2019
On 2019-05-20 16:58:58 +0000, gérard Calliet said:
> How doing something as simple as that in C, and not using the basic C
> rtl (atoi,...) ,
Um, what do you think I've been grumbling about for the better part of
a decade?
VSI is starting to address the down-revision tooling, but you're headed
into the distant past.
The doc is pretty thin in these and other areas, too:
http://h30266.www3.hpe.com/odl/i64os/opsys/vmsos84/5763/5763profile_019.html#date_time_chap
> because the idea is introducing normal young people (who don't know
> anything but C and Java) to the way something can be done with (very
> old) VAX C and VMS run-time, and also introducting The difference
> between C strings and string descriptors.
Descriptors? I wrote a few articles on that topic, too. And I've been
grumbling about the lack of integration of C and C++ with OpenVMS, and
about the tooling, and about the archaic frameworks, and about the
morass that are descriptors and logical names and itemlists and all the
glue code. It's a trip straight back to the 1980s, particularly the
system services. Most anybody that knows OO will probably recognize
descriptors. They won't like them and they'll think they're way too
primitive. But they'll recognize them.
Anybody that knows recent C will usually become frustrated by VAX C and
K&R, too. Having ported a bunch of code from K&R forward, I'd rather
not have to port code in the other direction...
Here's a long-winded and older version of a date comparison
else-platform (and slightly modified to document the return values),
using Objective C:
https://stackoverflow.com/a/34992094
NSString *dateString1 = @"Fri, 22 Jan 2016 10:46:50 +0530";
NSString *dateString2 = @"Fri, 22 Jan 2016 10:46:50 +0530";
NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
[inputFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss Z"];
NSDate *newDate = [inputFormatter dateFromString:dateString1];
NSDate *currentDate = [inputFormatter dateFromString:dateString2];
NSComparisonResult result = [newDate compare:currentDate]; //
comparing two dates
/*
NSComparisonResult can be either of these values:
- NSOrderedAscending (-1) //if date1 < date2
- NSOrderedSame (0) //if date1 = date2
- NSOrderedDescending (1) //if date1 > date2
*/
As for this case and for converting two date string to epoch and then
comparing them, hit Stack Overflow and start reading. For the folks
here on macOS, Dash.app is handy as that has a complete download of
Stack Overflow as one of its data sources.
As for C, you'll probably be using strptime here.
https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/rtref/strpti.htm
The following shows how to get to seconds...
http://pubs.opengroup.org/onlinepubs/9699919799/functions/strptime.html
And as for all of the reasons folks get themselves in a twist when
trying to run old versions far past what they should, I'm well aware.
I've heard most of the discussions before. And the folks will have
problems, as the servers are never as isolated as the folks believe.
Nor are the servers as reliably isolated. And the older the stuff gets
and the further behind it gets, the more expensive it gets.
--
Pure Personal Opinion | HoffmanLabs LLC
More information about the Info-vax
mailing list