~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/temporal.h

  • Committer: Monty Taylor
  • Date: 2009-03-08 23:45:12 UTC
  • mto: (923.2.1 mordred)
  • mto: This revision was merged to the branch mainline in revision 921.
  • Revision ID: mordred@inaugust.com-20090308234512-tqkygxtu1iaig23s
Removed C99 isnan() usage, which allows us to remove the util/math.{cc,h} workarounds. Yay for standards!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  Authors:
 
7
 *
 
8
 *  Jay Pipes <jay.pipes@sun.com>
5
9
 *
6
10
 *  This program is free software; you can redistribute it and/or modify
7
11
 *  it under the terms of the GNU General Public License as published by
43
47
#define DRIZZLED_TEMPORAL_H
44
48
 
45
49
#define DRIZZLE_MAX_SECONDS 59
46
 
#define DRIZZLE_MAX_SECONDS_WITH_LEAP 61
47
50
#define DRIZZLE_MAX_MINUTES 59
48
51
#define DRIZZLE_MAX_HOURS 23
49
52
#define DRIZZLE_MAX_DAYS 31
67
70
 
68
71
#define DRIZZLE_YY_PART_YEAR  70
69
72
 
70
 
#include <drizzled/calendar.h>
 
73
#include "drizzled/calendar.h"
71
74
 
72
 
#include <cassert>
73
75
#include <ostream>
74
76
 
75
77
/* Outside forward declarations */
76
 
namespace type {
77
 
class Decimal;
78
 
}
 
78
class my_decimal;
79
79
 
80
80
namespace drizzled
81
81
{
288
288
 
289
289
 
290
290
  /**
 
291
   * Operator overload for adding/subtracting a TemporalInterval
 
292
   * instance to this temporal.
 
293
   *
 
294
   * @param TemporalInterval instance to add/subtract to/from
 
295
   */
 
296
  Date& operator+=(const TemporalIntervalYear &rhs);
 
297
  Date& operator+=(const TemporalIntervalDayOrLess &rhs);
 
298
  Date& operator+=(const TemporalIntervalDayOrWeek &rhs);
 
299
  Date& operator+=(const TemporalIntervalYearMonth &rhs);
 
300
  Date& operator-=(const TemporalIntervalYear &rhs);
 
301
  Date& operator-=(const TemporalIntervalDayOrLess &rhs);
 
302
  Date& operator-=(const TemporalIntervalDayOrWeek &rhs);
 
303
  Date& operator-=(const TemporalIntervalYearMonth &rhs);
 
304
 
 
305
 
 
306
  /**
291
307
   * Operator overload for when a DateTime instance is
292
308
   * assigned to a Date.  We do a copy of the DateTime's
293
309
   * date-related components.
315
331
   * value.
316
332
   *
317
333
   * @param C-String to fill.
318
 
   * @param Length of to C-String
319
 
   * @returns length of string written (including trailing '\0').
320
 
   *          If output was truncated, returns length that would have
321
 
   *          been outputted.
322
 
   */
323
 
  virtual int to_string(char *to, size_t to_len) const;
324
 
 
325
 
  /**
326
 
   * Maximum length of C-String needed to represent type
327
 
   * (including '\0').
328
 
   */
329
 
  static const int MAX_STRING_LENGTH= 11;
 
334
   * @param Length of filled string (out param)
 
335
   */
 
336
  virtual void to_string(char *to, size_t *to_len) const;
330
337
 
331
338
  /**
332
339
   * Attempts to populate the Date instance based
336
343
   * successful.
337
344
   *
338
345
   * @param String to convert from
339
 
   * @param Length of supplied string (not including trailing '\0').
 
346
   * @param Length of supplied string
340
347
   */
341
348
  virtual bool from_string(const char *from, size_t from_len);
342
349
 
422
429
   *
423
430
   * @param Pointer to a time_t to convert to
424
431
   */
425
 
  virtual void to_time_t(time_t &to) const;
 
432
  virtual void to_time_t(time_t *to) const;
426
433
 
427
434
  /**
428
435
   * Attempts to populate the Date instance based
436
443
  virtual bool from_time_t(const time_t from);
437
444
 
438
445
  /**
439
 
   * Fills a supplied type::Decimal with a representation of
 
446
   * Fills a supplied my_decimal with a representation of
440
447
   * the Date value.
441
448
   *
442
 
   * @param Pointer to the type::Decimal to fill
 
449
   * @param Pointer to the my_decimal to fill
443
450
   */
444
 
  virtual void to_decimal(type::Decimal *to) const;
 
451
  virtual void to_decimal(my_decimal *to) const;
445
452
 
446
453
  friend class TemporalInterval;
447
454
  friend class Timestamp;
459
466
public:
460
467
  Time() :Temporal() {}
461
468
  /* Maximum number of seconds in 23:59:59 (24 * 60 * 60) */
462
 
  static const uint32_t MAX_CUMULATIVE_SECONDS= 86400L;
 
469
  const static uint32_t MAX_CUMULATIVE_SECONDS= 86400L;
463
470
 
464
471
  /**
465
472
   * Comparison operator overloads to compare a Time against
488
495
  bool is_valid_datetime() const {return false;}
489
496
  bool is_valid_time() const {return is_valid();}
490
497
  bool is_valid_timestamp() const {return false;}
491
 
 
492
498
  /** Returns whether the temporal value is valid date. */
493
499
  bool is_valid() const;
494
 
  bool is_fuzzy_valid() const;
495
500
 
496
501
  /**
497
502
   * Fills a supplied char string with a
498
503
   * string representation of the Time
499
504
   * value.
500
505
   *
501
 
   * @param C-String to fill
502
 
   * @param Length of to C-String
503
 
   * @returns length of string written (not including trailing '\0').
504
 
   *          If output was truncated, returns length that would have
505
 
   *          been outputted.
506
 
   */
507
 
  int to_string(char *to, size_t to_len) const;
508
 
 
509
 
  /**
510
 
   * Maximum length of C-String needed to represent type
511
 
   * (including '\0').
512
 
   */
513
 
  static const int MAX_STRING_LENGTH= 9;
514
 
 
 
506
   * @param C-String to fill.
 
507
   * @param Length of filled string (out param)
 
508
   */
 
509
  void to_string(char *to, size_t *to_len) const;
515
510
 
516
511
  /**
517
512
   * Attempts to populate the Time instance based
535
530
  void to_int32_t(int32_t *to) const;
536
531
 
537
532
  /**
538
 
   * Fills a supplied 8-byte integer pointer with an
539
 
   * integer representation of the Time
540
 
   * value. It is assume seconds past unix epoch
541
 
   *
542
 
   * @param Integer to fill.
543
 
   */
544
 
  void to_uint64_t(uint64_t &to) const;
545
 
 
546
 
  /**
547
533
   * Attempts to populate the Time instance based
548
534
   * on the contents of a supplied 4-byte integer.
549
535
   *
571
557
  bool from_time_t(const time_t from);
572
558
 
573
559
  /**
574
 
   * Fills a supplied type::Decimal with a representation of
 
560
   * Fills a supplied my_decimal with a representation of
575
561
   * the Time value.
576
562
   *
577
 
   * @param Pointer to the type::Decimal to fill
 
563
   * @param Pointer to the my_decimal to fill
578
564
   */
579
 
  void to_decimal(type::Decimal *to) const;
 
565
  void to_decimal(my_decimal *to) const;
580
566
 
581
567
  friend class Date;
582
568
  friend class DateTime;
612
598
   * string representation of the DateTime
613
599
   * value.
614
600
   *
615
 
   * @param C-String to fill
616
 
   * @param Length of to C-String
617
 
   * @returns length of string written (not including trailing '\0').
618
 
   *          If output was truncated, returns length that would have
619
 
   *          been outputted.
620
 
   */
621
 
  virtual int to_string(char *to, size_t to_len) const;
622
 
 
623
 
  /**
624
 
   * Maximum length of C-String needed to represent type
625
 
   * (including '\0').
626
 
   */
627
 
  static const int MAX_STRING_LENGTH= 27;
 
601
   * @param C-String to fill.
 
602
   * @param Length of filled string (out param)
 
603
   */
 
604
  virtual void to_string(char *to, size_t *to_len) const;
628
605
 
629
606
  /**
630
607
   * Attempts to populate the DateTime instance based
657
634
   * @param time_t to convert from
658
635
   */
659
636
  bool from_time_t(const time_t from);
660
 
  bool from_timeval(struct timeval &_timeval);
661
637
 
662
638
  /**
663
639
   * Attempts to populate the DateTime instance based
667
643
   * successful.
668
644
   *
669
645
   * @param Integer to convert from
670
 
   * @param convert if conversion to canonical representation
671
 
   *        should be attempted
672
646
   */
673
 
  bool from_int64_t(const int64_t from, bool convert);
674
 
 
675
 
  bool from_int64_t(const int64_t from) {
676
 
    return from_int64_t(from, true);
677
 
  }
 
647
  bool from_int64_t(const int64_t from);
678
648
 
679
649
  /**
680
650
   * Fills a supplied tm pointer with an
686
656
  void to_tm(struct tm *to) const;
687
657
 
688
658
  /**
689
 
   * Fills a supplied type::Decimal with a representation of
 
659
   * Fills a supplied my_decimal with a representation of
690
660
   * the DateTime value.
691
661
   *
692
 
   * @param Pointer to the type::Decimal to fill
 
662
   * @param Pointer to the my_decimal to fill
693
663
   */
694
 
  void to_decimal(type::Decimal *to) const;
 
664
  void to_decimal(my_decimal *to) const;
695
665
 
696
666
  friend class Timestamp;
697
667
};
753
723
   *
754
724
   * @param Pointer to a time_t to convert to
755
725
   */
756
 
  void to_time_t(time_t &to) const;
 
726
  void to_time_t(time_t *to) const;
757
727
};
758
728
 
759
729
/**
777
747
   * string representation of the MicroTimestamp
778
748
   * value.
779
749
   *
780
 
   * @param C-String to fill
781
 
   * @param Length of to C-String
782
 
   * @returns length of string written (not including trailing '\0').
783
 
   *          If output was truncated, returns length that would have
784
 
   *          been outputted.
785
 
   */
786
 
  int to_string(char *to, size_t to_len) const;
787
 
 
788
 
  /**
789
 
   * Maximum length of C-String needed to represent type
790
 
   * (including '\0').
791
 
   */
792
 
  static const int MAX_STRING_LENGTH= 27;
 
750
   * @param C-String to fill.
 
751
   * @param Length of filled string (out param)
 
752
   */
 
753
  void to_string(char *to, size_t *to_len) const;
793
754
 
794
755
  /**
795
756
   * Fills a supplied timeval pointer with an
801
762
   *
802
763
   * @param timeval to fill.
803
764
   */
804
 
  void to_timeval(struct timeval &to) const;
 
765
  void to_timeval(struct timeval *to) const;
805
766
};
806
767
 
807
768
/**