46 lines
1.6 KiB
Plaintext
46 lines
1.6 KiB
Plaintext
void local fn DoIt
|
|
CFStringRef monthString, zoneString, ampmString
|
|
long month, day, year, hour, minute
|
|
|
|
CFStringRef dateString = @"March 7 2009 7:30pm EST"
|
|
|
|
DateFormatterRef df = fn DateFormatterInit
|
|
DateFormatterSetDateStyle( df, NSDateFormatterMediumStyle )
|
|
DateFormatterSetTimeStyle( df, NSDateFormatterMediumStyle )
|
|
DateFormatterSetDateFormat( df, @"MMMM d YYYY h:ma" )
|
|
|
|
CFArrayRef months = fn DateFormatterMonthSymbols( df )
|
|
CFCharacterSetRef spaceSet = fn CharacterSetWhitespaceSet
|
|
|
|
ScannerRef scanner = fn ScannerWithString( dateString )
|
|
ScannerSetCharactersToBeSkipped( scanner, fn CharacterSetWithCharactersInString(@": ") )
|
|
|
|
fn ScannerScanUpToCharactersFromSet( scanner, spaceSet, @monthString )
|
|
fn ScannerScanInteger( scanner, @day )
|
|
fn ScannerScanInteger( scanner, @year )
|
|
fn ScannerScanInteger( scanner, @hour )
|
|
fn ScannerScanInteger( scanner, @minute )
|
|
fn ScannerScanUpToCharactersFromSet( scanner, spaceSet, @ampmString )
|
|
fn ScannerScanUpToCharactersFromSet( scanner, spaceSet, @zoneString )
|
|
|
|
month = fn ArrayIndexOfObject( months, monthString ) + 1
|
|
if ( fn StringIsEqual( ampmString, @"pm" ) ) then hour += 12
|
|
|
|
DateComponentsRef comps = fn DateComponentsInit
|
|
DateComponentsSetMonth( comps, month )
|
|
DateComponentsSetDay( comps, day )
|
|
DateComponentsSetYear( comps, year )
|
|
DateComponentsSetHour( comps, hour + 12 )
|
|
DateComponentsSetMinute( comps, minute )
|
|
|
|
CFDateRef dt = fn CalendarDateFromComponents( fn CalendarCurrent, comps )
|
|
CFStringRef string = fn DateFormatterStringFromDate( df, dt )
|
|
string = fn StringByAppendingFormat( string, @" %@", zoneString )
|
|
|
|
print string
|
|
end fn
|
|
|
|
fn DoIt
|
|
|
|
HandleEvents
|