VLCTime.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*****************************************************************************
  2. * VLCTime.m: VLCKit.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. @implementation VLCTime
  26. + (VLCTime *)nullTime
  27. {
  28. static VLCTime * nullTime = nil;
  29. if (!nullTime)
  30. nullTime = [[VLCTime timeWithNumber:nil] retain];
  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. return value ? [[value copy] autorelease] : nil;
  71. }
  72. - (NSString *)stringValue
  73. {
  74. if (value)
  75. {
  76. long long duration = [value longLongValue] / 1000000;
  77. return [NSString stringWithFormat:@"%02d:%02d:%02d",
  78. (long) (duration / 3600),
  79. (long)((duration / 60) % 60),
  80. (long) (duration % 60)];
  81. }
  82. else
  83. {
  84. // Return a string that represents an undefined time.
  85. return @"--:--:--";
  86. }
  87. }
  88. - (NSComparisonResult)compare:(VLCTime *)aTime
  89. {
  90. if (!aTime && !value)
  91. return NSOrderedSame;
  92. else if (!aTime)
  93. return NSOrderedDescending;
  94. else
  95. return [value compare:aTime.numberValue];
  96. }
  97. - (NSString *)description
  98. {
  99. return self.stringValue;
  100. }
  101. @end