libs-base/Source/NSDateIntervalFormatter.m

117 lines
2.7 KiB
Mathematica
Raw Normal View History

2019-10-12 16:42:18 +00:00
/* Implementation of class NSDateIntervalFormatter
Copyright (C) 2019 Free Software Foundation, Inc.
By: Gregory John Casamento <greg.casamento@gmail.com>
2019-10-12 16:42:18 +00:00
Date: Wed Oct 9 16:23:55 EDT 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#include <Foundation/NSDateIntervalFormatter.h>
#include <Foundation/NSLocale.h>
#include <Foundation/NSCalendar.h>
#include <Foundation/NSTimeZone.h>
#include <Foundation/NSString.h>
#include <Foundation/NSDate.h>
#include <Foundation/NSDateInterval.h>
2019-10-12 16:42:18 +00:00
@implementation NSDateIntervalFormatter
// Properties
- (NSLocale *) locale
{
return _locale;
}
- (void) setLocale: (NSLocale *)locale
{
ASSIGNCOPY(_locale, locale);
}
- (NSCalendar *) calendar
{
return _calendar;
}
- (void) setCalendar: (NSCalendar *)calendar
{
ASSIGNCOPY(_calendar, calendar);
}
- (NSTimeZone *) timeZone
{
return _timeZone;
}
- (void) setTimeZone: (NSTimeZone *)timeZone
{
ASSIGNCOPY(_timeZone, timeZone);
}
- (NSString *) dateTemplate
{
return _dateTemplate;
}
- (void) setDateTemplate: (NSString *)dateTemplate
{
ASSIGNCOPY(_dateTemplate, dateTemplate);
}
- (NSDateIntervalFormatterStyle) dateStyle
{
return _dateStyle;
}
- (void) setDateStyle: (NSDateIntervalFormatterStyle)dateStyle
{
_dateStyle = dateStyle;
}
- (NSDateIntervalFormatterStyle) timeStyle
{
return _timeStyle;
}
- (void) setTimeStyle: (NSDateIntervalFormatterStyle)timeStyle
{
_timeStyle = timeStyle;
}
// Create strings
2019-10-22 15:38:47 +00:00
- (NSString *) stringFromDate: (NSDate *)fromDate toDate: (NSDate *)toDate
{
NSDateInterval *interval = [[NSDateInterval alloc] initWithStartDate: fromDate
endDate: toDate];
AUTORELEASE(interval);
return [self stringFromDateInterval: interval];
}
2019-10-22 15:38:47 +00:00
- (NSString *) stringFromDateInterval: (NSDateInterval *)dateInterval
{
NSString *result = nil;
NSDate *fromDate = [dateInterval startDate];
NSDate *toDate = [dateInterval endDate];
result = [NSString stringWithFormat: @"%@ - %@", fromDate, toDate];
return result;
}
2019-10-12 16:42:18 +00:00
@end