source: releases/Pester/1.1b4/Source/PSTimeDateEditor.m@ 535

Last change on this file since 535 was 102, checked in by Nicholas Riley, 22 years ago

Pester 1.1b3

File size: 2.0 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 static NJRDateFormatter *timeFormatter = nil, *dateFormatter = nil;
17 if (timeFormatter == nil) {
18 timeFormatter = [[NJRDateFormatter alloc] initWithDateFormat: [NJRDateFormatter localizedTimeFormatIncludingSeconds: NO] allowNaturalLanguage: YES];
19 dateFormatter = [[NJRDateFormatter alloc] initWithDateFormat: [NJRDateFormatter localizedDateFormatIncludingWeekday: NO] allowNaturalLanguage: YES];
20 }
21 [timeOfDay setFormatter: timeFormatter];
22 [timeDate setFormatter: dateFormatter];
23 [timeDate setObjectValue: [NSDate date]];
24
25 // add completions
26 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
27 NSArray *dayNames = [defaults arrayForKey: NSWeekDayNameArray];
28 NSArray *completions = [timeDateCompletions itemTitles];
29 NSEnumerator *e = [completions objectEnumerator];
30 NSString *title;
31 int itemIndex = 0;
32 NSRange matchingRange;
33 while ( (title = [e nextObject]) != nil) {
34 matchingRange = [title rangeOfString: @"ÇdayÈ"];
35 if (matchingRange.location != NSNotFound) {
36 NSMutableString *format = [title mutableCopy];
37 NSEnumerator *we = [dayNames objectEnumerator];
38 NSString *dayName;
39 [format deleteCharactersInRange: matchingRange];
40 [format insertString: @"%@" atIndex: matchingRange.location];
41 [timeDateCompletions removeItemAtIndex: itemIndex];
42 while ( (dayName = [we nextObject]) != nil) {
43 [timeDateCompletions insertItemWithTitle: [NSString stringWithFormat: format, dayName] atIndex: itemIndex];
44 itemIndex++;
45 }
46 } else itemIndex++;
47 }
48}
49
50@end
Note: See TracBrowser for help on using the repository browser.