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 » U++ Library : Other (not classified elsewhere) » [FEATURE REQUEST] Time to UTC ISO 8601 and UTC ISO 8601 to Time
[FEATURE REQUEST] Time to UTC ISO 8601 and UTC ISO 8601 to Time [message #14041] Thu, 07 February 2008 15:39 Go to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
UTC time formatted by ISO 8601 standard is very common now and is the default DateTime format for all XML documents. It would be great to have simple functions that can turn a Time object into a UTC ISO 8601 formatted String and also to create a Time object from a UTC ISO 8601 String.

Creating a UTC String is as simple as:
String utc = FormatTime(t, "YYYY-DD-MMThh:mm:ss");

But converting a UTC String to Time is a bit more difficult. I have tried to use the StrToDate(time_object, utc_string) function, and it does parse the date correctly, but I can only receive a Date object from this, not the time details as well.

StrToTime would be great, especially with UTC ISO 8601 support.

Thanks.
Re: [FEATURE REQUEST] Time to UTC ISO 8601 and UTC ISO 8601 to Time [message #14047 is a reply to message #14041] Thu, 07 February 2008 22:21 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
captainc wrote on Thu, 07 February 2008 09:39

UTC time formatted by ISO 8601 standard is very common now and is the default DateTime format for all XML documents. It would be great to have simple functions that can turn a Time object into a UTC ISO 8601 formatted String and also to create a Time object from a UTC ISO 8601 String.

Creating a UTC String is as simple as:
String utc = FormatTime(t, "YYYY-DD-MMThh:mm:ss");

But converting a UTC String to Time is a bit more difficult. I have tried to use the StrToDate(time_object, utc_string) function, and it does parse the date correctly, but I can only receive a Date object from this, not the time details as well.

StrToTime would be great, especially with UTC ISO 8601 support.

Thanks.


I would be glad to accept contributed implementation Smile

Mirek
Re: [FEATURE REQUEST] Time to UTC ISO 8601 and UTC ISO 8601 to Time [message #18334 is a reply to message #14047] Tue, 23 September 2008 13:52 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello luzr

Please check if it could serve.

Best regards
Koldo

const char *StrToTime(Time& d, const char *s)
{
	s = StrToDate(d, s);
	
	d.hour = 0;
	d.minute = 0;
	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;
}


Best regards
Iñaki
Re: [FEATURE REQUEST] Time to UTC ISO 8601 and UTC ISO 8601 to Time [message #18336 is a reply to message #18334] Tue, 23 September 2008 17:37 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Maybe we should add "UTC" to the name?

Mirek
Re: [FEATURE REQUEST] Time to UTC ISO 8601 and UTC ISO 8601 to Time [message #18345 is a reply to message #18336] Tue, 23 September 2008 22:04 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Well...

I do not have any idea about that but reading in wikipedia they say:

"So a time might appear as either "134730" in the basic format or "13:47:30" in the extended format."

The function I have inclosed runs well with "13:47:30", "13.47.30" and "13/47/30" for example, but not with "134730".

So, if you prefer this behaviour I will change the function.

Best regards
Koldo


Best regards
Iñaki
Re: [FEATURE REQUEST] Time to UTC ISO 8601 and UTC ISO 8601 to Time [message #18365 is a reply to message #18345] Wed, 24 September 2008 22:18 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Oh, I guess there must be some misunderstanding...

All that I was proposing was to somehow quote 'UTC' in the function name.

One reason is that "normal" Format (Scan) should follow localization settings (eventually..).

Well, now seeing the code, I guess that call to StrToDate is not a good idea in this respect too Smile (StrToDate respects localization).

IMO, we need both - StrToTime and UTCToTime + FormatUTC, what do you think?

Mirek

[Updated on: Wed, 24 September 2008 22:18]

Report message to a moderator

Re: [FEATURE REQUEST] Time to UTC ISO 8601 and UTC ISO 8601 to Time [message #18404 is a reply to message #18365] Fri, 26 September 2008 12:04 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Luzr

Simpler than that. Tell me function names, what you want them to do, give me some samples and I will do them.

Best regards
Koldo


Best regards
Iñaki
Re: [FEATURE REQUEST] Time to UTC ISO 8601 and UTC ISO 8601 to Time [message #18475 is a reply to message #18404] Thu, 02 October 2008 21:32 Go to previous messageGo to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
Simple function I used in my program:
Time UTCStrToTime(String utc_str){
	//utc example: 2006-01-04T21:59:11
	int year = StrInt(utc_str.Left(4));
	int month = StrInt(utc_str.Mid(5,2));
	int day = StrInt(utc_str.Mid(8,2));
	int hour = StrInt(utc_str.Mid(11,2));
	int minute = StrInt(utc_str.Mid(14,2));
	int second = StrInt(utc_str.Mid(17,2));
	return Time(year, month, day, hour, minute, second);
}

Re: [FEATURE REQUEST] Time to UTC ISO 8601 and UTC ISO 8601 to Time [message #18481 is a reply to message #18475] Fri, 03 October 2008 07:51 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hey Luzr

Do you imagine?. You have more than one option to choose!

Every day we are more people using and supporting Upp.

Koldo


Best regards
Iñaki
Re: [FEATURE REQUEST] Time to UTC ISO 8601 and UTC ISO 8601 to Time [message #18505 is a reply to message #18481] Sat, 04 October 2008 22:53 Go to previous message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
Yeah, but I didn't check the length... so that needs to be fixed.
Previous Topic: Small Correction about Vista/GLCtrl corrections
Next Topic: Missing methods in Win32 version of GLCtrl
Goto Forum:
  


Current Time: Fri Mar 29 14:46:48 CET 2024

Total time taken to generate the page: 0.01697 seconds