VLCTime.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*****************************************************************************
  2. * VLCTime.h: VLC.framework VLCTime implementation
  3. *****************************************************************************
  4. * Copyright (C) 2007 Pierre d'Herbemont
  5. * Copyright (C) 2007 the VideoLAN team
  6. * $Id$
  7. *
  8. * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23. *****************************************************************************/
  24. #import <VLCTime.h>
  25. static VLCTime *nullTime = nil;
  26. @implementation VLCTime
  27. + (VLCTime *)nullTime
  28. {
  29. if (!nullTime)
  30. nullTime = [VLCTime timeWithNumber:[NSNumber numberWithInt:0]];
  31. return nullTime;
  32. }
  33. + (VLCTime *)timeWithNumber:(NSNumber *)aNumber
  34. {
  35. return [[[VLCTime alloc] initWithNumber:aNumber] autorelease];
  36. }
  37. // TODO: Implement [VLCTime timeWithString]
  38. //+ (VLCTime *)timeWithString:(NSString *)aString
  39. //{
  40. // return [[[VLCTime alloc] initWithString:aString] autorelease];
  41. //}
  42. - (id)initWithNumber:(NSNumber *)aNumber
  43. {
  44. if (self = [super init])
  45. {
  46. if (aNumber)
  47. value = [[aNumber copy] retain];
  48. else
  49. value = nil;
  50. }
  51. return self;
  52. }
  53. // TODO: Implement [VLCTime initWithString]
  54. //- (id)initWithString:(NSString *)aString
  55. //{
  56. // // Sounds like a good idea but I really don't think there is any value added
  57. // if (self = [super init])
  58. // {
  59. // // convert value
  60. // }
  61. // return self;
  62. //}
  63. - (void)dealloc
  64. {
  65. [value release];
  66. [super dealloc];
  67. }
  68. - (NSNumber *)numberValue
  69. {
  70. if (value)
  71. return [value copy];
  72. else
  73. return nil;
  74. }
  75. - (NSString *)stringValue
  76. {
  77. if (value)
  78. {
  79. long long duration = [value longLongValue] / 1000000;
  80. return [NSString stringWithFormat:@"%02d:%02d:%02d",
  81. (long) (duration / 3600),
  82. (long)((duration / 60) % 60),
  83. (long) (duration % 60)];
  84. }
  85. else
  86. {
  87. // Return a string that represents an undefined time.
  88. return @"--:--:--";
  89. }
  90. }
  91. - (NSComparisonResult)compare:(VLCTime *)aTime
  92. {
  93. if (!aTime && !value)
  94. return NSOrderedSame;
  95. else if (!aTime)
  96. return NSOrderedDescending;
  97. else
  98. return [value compare:[aTime numberValue]];
  99. }
  100. - (NSString *)description
  101. {
  102. return [self stringValue];
  103. }
  104. @end