~ubuntu-branches/ubuntu/trusty/gnustep-base/trusty

« back to all changes in this revision

Viewing changes to Source/NSCalendarDate.m

Tags: upstream-1.11.2
ImportĀ upstreamĀ versionĀ 1.11.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
   You should have received a copy of the GNU Library General Public
23
23
   License along with this library; if not, write to the Free
24
 
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
 
24
   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
25
25
 
26
26
   <title>NSCalendarDate class reference</title>
27
 
   $Date: 2005/02/22 11:22:43 $ $Revision: 1.102 $
 
27
   $Date: 2005/11/06 13:53:39 $ $Revision: 1.112 $
28
28
   */
29
29
 
30
30
#include "config.h"
60
60
#define GREGORIAN_REFERENCE 730486
61
61
 
62
62
@class  GSTimeZone;
 
63
@interface      GSTimeZone : NSObject   // Help the compiler
 
64
@end
63
65
@class  GSAbsTimeZone;
 
66
@interface      GSAbsTimeZone : NSObject        // Help the compiler
 
67
@end
 
68
@class  NSGDate;
 
69
@interface      NSGDate : NSObject      // Help the compiler
 
70
@end
 
71
 
64
72
 
65
73
static NSString *cformat = @"%Y-%m-%d %H:%M:%S %z";
66
74
 
276
284
  *mil = (a - h - m - c) * 1000;
277
285
}
278
286
 
279
 
@class  NSGDate;
280
 
 
281
287
/**
282
288
 * An [NSDate] subclass which understands about timezones and provides
283
289
 * methods for dealing with date and time information by calendar and
600
606
  BOOL          ampm = NO;
601
607
  BOOL          twelveHrClock = NO;
602
608
  int           julianWeeks = -1, weekStartsMonday = 0, dayOfWeek = -1;
603
 
  const char    *source = [description cString];
604
 
  unsigned      sourceLen = strlen(source);
 
609
  const char    *source;
 
610
  unsigned      sourceLen;
605
611
  unichar       *format;
606
612
  unsigned      formatLen;
607
613
  unsigned      formatIdx = 0;
615
621
  BOOL          changedFormat = NO;
616
622
  BOOL          error = NO;
617
623
 
 
624
  if (description == nil)
 
625
    {
 
626
      description = @"";
 
627
    }
 
628
  source = [description cString];
 
629
  sourceLen = strlen(source);
618
630
  if (locale == nil)
619
631
    {
620
632
      locale = GSUserDefaultsDictionaryRepresentation();
627
639
          fmt = @"";
628
640
        }
629
641
    }
630
 
  if (description == nil)
631
 
    {
632
 
      description = @"";
633
 
    }
634
642
 
635
643
  /*
636
644
   * Get format into a buffer, leaving room for expansion in case it has
1606
1614
}
1607
1615
 
1608
1616
/**
1609
 
 * Calls -descriptionWithCalendarFormat:locale: passing the receviers
 
1617
 * Calls -descriptionWithCalendarFormat:locale: passing the receiver's
1610
1618
 * calendar format and a nil locale.
1611
1619
 */
1612
1620
- (NSString*) description
1742
1750
                ycent = YES;
1743
1751
              case 'y':
1744
1752
                v = info->yd;
1745
 
                if (v < 0)
1746
 
                  v = 0;
1747
 
                if (v > 9999)
1748
 
                  v = 9999;
1749
1753
                if (ycent)
1750
1754
                  {
1751
 
                    Grow(info, 4);
1752
 
                    info->t[info->offset+3] = (v%10) + '0';
1753
 
                    v /= 10;
1754
 
                    info->t[info->offset+2] = (v%10) + '0';
1755
 
                    v /= 10;
1756
 
                    info->t[info->offset+1] = (v%10) + '0';
1757
 
                    v /= 10;
1758
 
                    info->t[info->offset+0] = (v%10) + '0';
1759
 
                    info->offset += 4;
 
1755
                    if (v >= 0 && v <= 9999)
 
1756
                      {
 
1757
                        Grow(info, 4);
 
1758
                        info->t[info->offset+3] = (v%10) + '0';
 
1759
                        v /= 10;
 
1760
                        info->t[info->offset+2] = (v%10) + '0';
 
1761
                        v /= 10;
 
1762
                        info->t[info->offset+1] = (v%10) + '0';
 
1763
                        v /= 10;
 
1764
                        info->t[info->offset+0] = (v%10) + '0';
 
1765
                        info->offset += 4;
 
1766
                      }
 
1767
                    else
 
1768
                      {
 
1769
                        unsigned char   tmp[16];
 
1770
                        int             idx = 0;
 
1771
 
 
1772
                        sprintf((char*)tmp, "%d", v);
 
1773
                        Grow(info, strlen((char*)tmp));
 
1774
                        while (tmp[idx] != '\0')
 
1775
                          {
 
1776
                            info->t[info->offset++] = tmp[idx++];
 
1777
                          }
 
1778
                      }
1760
1779
                  }
1761
1780
                else
1762
1781
                  {
1763
1782
                    Grow(info, 2);
 
1783
                    if (v < 0) v = -v;
1764
1784
                    v = v % 100;
1765
1785
                    info->t[info->offset+1] = (v%10) + '0';
1766
1786
                    v /= 10;
1845
1865
                  s -= (_seconds_since_ref + offset(_time_zone, self));
1846
1866
                  s = fabs(s);
1847
1867
                  s -= floor(s);
1848
 
                  v = (int)s;
 
1868
                  v = (int)(s * 1000);
1849
1869
                }
1850
1870
                Grow(info, 3);
1851
1871
                info->t[info->offset+2] = (v%10) + '0';
2394
2414
      minute %= 60;
2395
2415
      if (minute < 0)
2396
2416
        {
2397
 
          hours++;
 
2417
          hours--;
2398
2418
          minute += 60;
2399
2419
        }
2400
2420
 
2538
2558
          eday += 31;
2539
2559
        }
2540
2560
    }
2541
 
  if (emonth < smonth)
 
2561
  if (emonth < smonth || (emonth == smonth && eday < sday))
2542
2562
    {
2543
2563
      eyear -= 1;
2544
2564
      emonth += 12;
2565
2585
    }
2566
2586
  else
2567
2587
    {
2568
 
      while (diff--)
 
2588
      while (diff-- > 0)
2569
2589
        {
2570
2590
          int tmpmonth = emonth - diff - 1;
2571
2591
          int tmpyear = eyear;