Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » LineEdit, EditFields, DocEdit » Scan an timestamp
Scan an timestamp [message #27369] Wed, 14 July 2010 22:10 Go to next message
mubeta is currently offline  mubeta
Messages: 77
Registered: October 2006
Member
Hi,
please, how I can scan this string of timestamp: "Wed, 14 Jul 2010 18:07:49 GMT", to a Time?

thanks.
Re: Scan an timestamp [message #27370 is a reply to message #27369] Wed, 14 July 2010 23:05 Go to previous message
koldo is currently offline  koldo
Messages: 3268
Registered: August 2008
Senior Veteran
mubeta wrote on Wed, 14 July 2010 22:10

Hi,
please, how I can scan this string of timestamp: "Wed, 14 Jul 2010 18:07:49 GMT", to a Time?

thanks.

Hello Mubeta

If you remove the initial "Wed," you can use this:

// Like StrToDate but using Time
const char *StrToTime(struct Upp::Time& d, const char *s) {
	s = StrToDate(d, s);

	d.hour = d.minute = d.second = 0;

	const char *fmt = "hms";

	while(*fmt) {
		while(*s && !IsDigit(*s))
			s++;
		int n;
		if(IsDigit(*s)) {
			char *q;
			n = strtoul(s, &q, 10);
			s = q;
		} else
			break;

		switch(*fmt) {
		case 'h':
			if(n < 0 || n > 23)
				return NULL;
			d.hour = n;
			break;
		case 'm':
			if(n < 0 || n > 59)
				return NULL;
			d.minute = n;
			break;
		case 's':
			if(n < 0 || n > 59)
				return NULL;
			d.second = n;
			break;
		default:
			NEVER();
		}
		fmt++;
	}
	return d.IsValid() ? s : NULL;
}

Time StrToTime(const char *s) {
	Time ret;
	StrToTime(ret, s);
	return ret;
}


So

	SetDateScan("dmy"); // Or set a language with the right date scan order
	Time t = StrToTime("14 Jul 2010 18:07:49 GMT");


Best regards
IƱaki
Previous Topic: DocEdit appned, highlight, mouse events
Next Topic: Is there a way to make EditDouble return 0 if it has no value?
Goto Forum:
  


Current Time: Sat Oct 23 16:19:49 CEST 2021

Total time taken to generate the page: 0.01197 seconds