source: trunk/Cocoa/Pester/Source/PSTimeDateEditor.m@ 504

Last change on this file since 504 was 360, checked in by Nicholas Riley, 17 years ago

Pester.xcodeproj: Add Perl embedding bits; remove SoundFileManager.h.

DynaLoader.a: i386/ppc version from Tiger; Leopard's version causes
Tiger to crash.

Info-Pester.plist: Updated copyright date.

Read Me.rtfd: Remove .typeAttributes.dict, no longer used; update a
bit.

PSTimeDateEditor.m: Switch to NJRDateFormatters again.

NJRDateFormatter.[hm]: Removed old-style date formatter workarounds;
added code for using Date::Manip and trying multiple ICU-based date
formatters.

English.lproj/InfoPlist.strings: Updated copyright date.

English.lproj/MainMenu.nib: Modified date completion menu for items
Date::Manip can parse.

Manip.pm: Date::Manip 5.47, converted to UTF-8.

File size: 2.2 KB
Line 
1//
2// PSTimeDateEditor.m
3// Pester
4//
5// Created by Nicholas Riley on Sun Feb 16 2003.
6// Copyright (c) 2003 Nicholas Riley. All rights reserved.
7//
8
9#import "PSTimeDateEditor.h"
10#import "NJRDateFormatter.h"
11
12@implementation PSTimeDateEditor
13
14+ (void)setUpTimeField:(NSTextField *)timeOfDay dateField:(NSTextField *)timeDate completions:(NSPopUpButton *)timeDateCompletions;
15{
16 [[NJRDateFormatter alloc] init]; // XXX testing
17 [NSDateFormatter setDefaultFormatterBehavior: NSDateFormatterBehavior10_4];
18 static NSDateFormatter *timeFormatter = nil, *dateFormatter = nil;
19 if (timeFormatter == nil) {
20 timeFormatter = [[NJRDateFormatter timeFormatter] retain];
21 [timeFormatter setLenient: YES];
22 [timeFormatter setDateStyle: NSDateFormatterNoStyle];
23 [timeFormatter setTimeStyle: NSDateFormatterShortStyle];
24 dateFormatter = [[NJRDateFormatter dateFormatter] retain];
25 [dateFormatter setLenient: YES];
26 [dateFormatter setDateStyle: NSDateFormatterLongStyle];
27 [dateFormatter setTimeStyle: NSDateFormatterNoStyle];
28 }
29 [timeOfDay setFormatter: timeFormatter];
30 [timeDate setFormatter: dateFormatter];
31 [timeDate setObjectValue: [NSDate date]];
32
33 // add completions
34 NSArray *dayNames = [dateFormatter weekdaySymbols];
35 NSArray *completions = [timeDateCompletions itemTitles];
36 NSEnumerator *e = [completions objectEnumerator];
37 NSString *title;
38 int itemIndex = 0;
39 NSRange matchingRange;
40 while ( (title = [e nextObject]) != nil) {
41 matchingRange = [title rangeOfString: @"«day»"];
42 if (matchingRange.location != NSNotFound) {
43 NSMutableString *format = [title mutableCopy];
44 NSEnumerator *we = [dayNames objectEnumerator];
45 NSString *dayName;
46 [format deleteCharactersInRange: matchingRange];
47 [format insertString: @"%@" atIndex: matchingRange.location];
48 [timeDateCompletions removeItemAtIndex: itemIndex];
49 while ( (dayName = [we nextObject]) != nil) {
50 [timeDateCompletions insertItemWithTitle: [NSString stringWithFormat: format, dayName] atIndex: itemIndex];
51 itemIndex++;
52 }
53 [format release];
54 } else itemIndex++;
55 }
56}
57
58@end
Note: See TracBrowser for help on using the repository browser.