FROM : Brian Stern
DATE : Thu Jun 22 18:40:31 2006
At 1:11 PM -0300 6/22/06, Neto wrote:
>
>Anyway...just thoughts, because I don't know how to implement the
>"checkCurrentSystemDateFormat" or the "checkFirstTwoCharacters" methods.
Use NSScanner for checkFirstTwoCharacters.
http://developer.apple.com/documentation/Cocoa/Conceptual/Strings/Articles/Scanners.html
This code has worked for me to determine the system date format:
static BOOL sDayBeforeMonth; // Date format is dmy or mdy
// =======================================================================
// determineDateFormat
// =======================================================================
// Gets the user setting for date formatting, either MDY or DMY
// Also look at NSShortDateFormatString or NSDateFormatString
// NSDateTimeOrdering doesn't work. It's apparently MDYH on all computers.
// NSShortDateFormatString is %1m/%e/%y on a US machine. Can be displayed with
// defaults read NSGlobalDomain NSShortDateFormatString
- (void)determineDateFormat
{
NSString* f = [[NSUserDefaults standardUserDefaults]
objectForKey:NSShortDateFormatString];
// NSLog(@"%@ %@", f, NSShortDateFormatString);
NSRange rMonth, rDay;
rMonth = [f rangeOfString:@"m"];
if (rMonth.length == 0)
rMonth = [f rangeOfString:@"b"];// not sure if this can happen
if (rMonth.length == 0)
rMonth = [f rangeOfString:@"B"];// not sure if this can happen
rDay = [f rangeOfString:@"e"];
if (rDay.length == 0)
rDay = [f rangeOfString:@"d"]; // not sure if this can happen
// Is it US format or EUR format?
// MDYH or DMYH @"%m/%d/%Y" or @"%d/%m/%Y"
// The default in the nib is EUR format
// Change to US format if we need to
if (rMonth.location < rDay.location) // User is US format
{
sDayBeforeMonth = NO; // US format
}
else
{
sDayBeforeMonth = YES; // EUR format
}
// NSLog(@"sDayBeforeMonth: %@", sDayBeforeMonth ? @"YES":@"NO");
}
// Return whether the user's date format is dmy, which is european style.
// returns false if user's date format is mdy, american style.
+ (BOOL)dateFormatIsDayBeforeMonth
{
return sDayBeforeMonth;
}
--
Brian Stern
<email_removed>
DATE : Thu Jun 22 18:40:31 2006
At 1:11 PM -0300 6/22/06, Neto wrote:
>
>Anyway...just thoughts, because I don't know how to implement the
>"checkCurrentSystemDateFormat" or the "checkFirstTwoCharacters" methods.
Use NSScanner for checkFirstTwoCharacters.
http://developer.apple.com/documentation/Cocoa/Conceptual/Strings/Articles/Scanners.html
This code has worked for me to determine the system date format:
static BOOL sDayBeforeMonth; // Date format is dmy or mdy
// =======================================================================
// determineDateFormat
// =======================================================================
// Gets the user setting for date formatting, either MDY or DMY
// Also look at NSShortDateFormatString or NSDateFormatString
// NSDateTimeOrdering doesn't work. It's apparently MDYH on all computers.
// NSShortDateFormatString is %1m/%e/%y on a US machine. Can be displayed with
// defaults read NSGlobalDomain NSShortDateFormatString
- (void)determineDateFormat
{
NSString* f = [[NSUserDefaults standardUserDefaults]
objectForKey:NSShortDateFormatString];
// NSLog(@"%@ %@", f, NSShortDateFormatString);
NSRange rMonth, rDay;
rMonth = [f rangeOfString:@"m"];
if (rMonth.length == 0)
rMonth = [f rangeOfString:@"b"];// not sure if this can happen
if (rMonth.length == 0)
rMonth = [f rangeOfString:@"B"];// not sure if this can happen
rDay = [f rangeOfString:@"e"];
if (rDay.length == 0)
rDay = [f rangeOfString:@"d"]; // not sure if this can happen
// Is it US format or EUR format?
// MDYH or DMYH @"%m/%d/%Y" or @"%d/%m/%Y"
// The default in the nib is EUR format
// Change to US format if we need to
if (rMonth.location < rDay.location) // User is US format
{
sDayBeforeMonth = NO; // US format
}
else
{
sDayBeforeMonth = YES; // EUR format
}
// NSLog(@"sDayBeforeMonth: %@", sDayBeforeMonth ? @"YES":@"NO");
}
// Return whether the user's date format is dmy, which is european style.
// returns false if user's date format is mdy, american style.
+ (BOOL)dateFormatIsDayBeforeMonth
{
return sDayBeforeMonth;
}
--
Brian Stern
<email_removed>
| Related mails | Author | Date |
|---|---|---|
| Neto | Jun 22, 17:11 | |
| Andreas Mayer | Jun 22, 17:37 | |
| George Orthwein | Jun 22, 17:42 | |
| Neto | Jun 22, 18:11 | |
| Brian Stern | Jun 22, 18:40 | |
| Andreas Mayer | Jun 22, 18:58 | |
| Neto | Jun 22, 19:03 |






Cocoa mail archive

