~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/tztime.cc

  • Committer: Monty Taylor
  • Date: 2008-07-31 18:25:59 UTC
  • mto: (202.3.5 gettextize)
  • mto: This revision was merged to the branch mainline in revision 243.
  • Revision ID: monty@inaugust.com-20080731182559-txjt9f3dfhusxfp8
Renamed MYSQL_TIME to DRIZZLE_TIME.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
/*
45
45
  Structure with information describing ranges of my_time_t shifted to local
46
 
  time (my_time_t + offset). Used for local MYSQL_TIME -> my_time_t conversion.
 
46
  time (my_time_t + offset). Used for local DRIZZLE_TIME -> my_time_t conversion.
47
47
  See comments for TIME_to_gmt_sec() for more info.
48
48
*/
49
49
typedef struct revtinfo
130
130
      offset - local time zone offset
131
131
 
132
132
  DESCRIPTION
133
 
    Convert my_time_t with offset to MYSQL_TIME struct. Differs from timesub
 
133
    Convert my_time_t with offset to DRIZZLE_TIME struct. Differs from timesub
134
134
    (from elsie code) because doesn't contain any leap correction and
135
135
    TM_GMTOFF and is_dst setting and contains some MySQL specific
136
136
    initialization. Funny but with removing of these we almost have
137
137
    glibc's offtime function.
138
138
*/
139
139
static void
140
 
sec_to_TIME(MYSQL_TIME * tmp, my_time_t t, long offset)
 
140
sec_to_TIME(DRIZZLE_TIME * tmp, my_time_t t, long offset)
141
141
{
142
142
  long days;
143
143
  long rem;
193
193
  tmp->month++;
194
194
  tmp->day= (uint)(days + 1);
195
195
 
196
 
  /* filling MySQL specific MYSQL_TIME members */
 
196
  /* filling MySQL specific DRIZZLE_TIME members */
197
197
  tmp->neg= 0; tmp->second_part= 0;
198
 
  tmp->time_type= MYSQL_TIMESTAMP_DATETIME;
 
198
  tmp->time_type= DRIZZLE_TIMESTAMP_DATETIME;
199
199
}
200
200
 
201
201
 
285
285
 
286
286
/*
287
287
  Converts time in my_time_t representation (seconds in UTC since Epoch) to
288
 
  broken down MYSQL_TIME representation in local time zone.
 
288
  broken down DRIZZLE_TIME representation in local time zone.
289
289
 
290
290
  SYNOPSIS
291
291
    gmt_sec_to_TIME()
300
300
    (60th and 61st second, look how we calculate them as "hit" in this
301
301
    function).
302
302
    Under realistic assumptions about frequency of transitions the same array
303
 
    can be used fot MYSQL_TIME -> my_time_t conversion. For this we need to
 
303
    can be used fot DRIZZLE_TIME -> my_time_t conversion. For this we need to
304
304
    implement tweaked binary search which will take into account that some
305
 
    MYSQL_TIME has two matching my_time_t ranges and some of them have none.
 
305
    DRIZZLE_TIME has two matching my_time_t ranges and some of them have none.
306
306
*/
307
307
static void
308
 
gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t sec_in_utc, const TIME_ZONE_INFO *sp)
 
308
gmt_sec_to_TIME(DRIZZLE_TIME *tmp, my_time_t sec_in_utc, const TIME_ZONE_INFO *sp)
309
309
{
310
310
  const TRAN_TYPE_INFO *ttisp;
311
311
  const LS_INFO *lp;
407
407
}
408
408
 
409
409
/*
410
 
  Converts local time in broken down MYSQL_TIME representation to my_time_t
 
410
  Converts local time in broken down DRIZZLE_TIME representation to my_time_t
411
411
  representation.
412
412
 
413
413
  SYNOPSIS
449
449
 
450
450
    We use completely different approach. It is better since it is both
451
451
    faster than iterative implementations and fully determenistic. If you
452
 
    look at my_time_t to MYSQL_TIME conversion then you'll find that it consist
 
452
    look at my_time_t to DRIZZLE_TIME conversion then you'll find that it consist
453
453
    of two steps:
454
454
    The first is calculating shifted my_time_t value and the second - TIME
455
455
    calculation from shifted my_time_t value (well it is a bit simplified
479
479
    0 in case of error.
480
480
*/
481
481
static my_time_t
482
 
TIME_to_gmt_sec(const MYSQL_TIME *t, const TIME_ZONE_INFO *sp,
 
482
TIME_to_gmt_sec(const DRIZZLE_TIME *t, const TIME_ZONE_INFO *sp,
483
483
                bool *in_dst_time_gap)
484
484
{
485
485
  my_time_t local_t;
602
602
{
603
603
public:
604
604
  Time_zone_system() {}                       /* Remove gcc warning */
605
 
  virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t,
 
605
  virtual my_time_t TIME_to_gmt_sec(const DRIZZLE_TIME *t,
606
606
                                    bool *in_dst_time_gap) const;
607
 
  virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const;
 
607
  virtual void gmt_sec_to_TIME(DRIZZLE_TIME *tmp, my_time_t t) const;
608
608
  virtual const String * get_name() const;
609
609
};
610
610
 
611
611
 
612
612
/*
613
 
  Converts local time in system time zone in MYSQL_TIME representation
 
613
  Converts local time in system time zone in DRIZZLE_TIME representation
614
614
  to its my_time_t representation.
615
615
 
616
616
  SYNOPSIS
617
617
    TIME_to_gmt_sec()
618
 
      t               - pointer to MYSQL_TIME structure with local time in
 
618
      t               - pointer to DRIZZLE_TIME structure with local time in
619
619
                        broken-down representation.
620
620
      in_dst_time_gap - pointer to bool which is set to true if datetime
621
621
                        value passed doesn't really exist (i.e. falls into
623
623
 
624
624
  DESCRIPTION
625
625
    This method uses system function (localtime_r()) for conversion
626
 
    local time in system time zone in MYSQL_TIME structure to its my_time_t
 
626
    local time in system time zone in DRIZZLE_TIME structure to its my_time_t
627
627
    representation. Unlike the same function for Time_zone_db class
628
628
    it it won't handle unnormalized input properly. Still it will
629
629
    return lowest possible my_time_t in case of ambiguity or if we
635
635
    Corresponding my_time_t value or 0 in case of error
636
636
*/
637
637
my_time_t
638
 
Time_zone_system::TIME_to_gmt_sec(const MYSQL_TIME *t, bool *in_dst_time_gap) const
 
638
Time_zone_system::TIME_to_gmt_sec(const DRIZZLE_TIME *t, bool *in_dst_time_gap) const
639
639
{
640
640
  long not_used;
641
641
  return my_system_gmt_sec(t, &not_used, in_dst_time_gap);
648
648
 
649
649
  SYNOPSIS
650
650
    gmt_sec_to_TIME()
651
 
      tmp - pointer to MYSQL_TIME structure to fill-in
 
651
      tmp - pointer to DRIZZLE_TIME structure to fill-in
652
652
      t   - my_time_t value to be converted
653
653
 
654
654
  NOTE
659
659
    the 1902 easily.
660
660
*/
661
661
void
662
 
Time_zone_system::gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const
 
662
Time_zone_system::gmt_sec_to_TIME(DRIZZLE_TIME *tmp, my_time_t t) const
663
663
{
664
664
  struct tm tmp_tm;
665
665
  time_t tmp_t= (time_t)t;
666
666
 
667
667
  localtime_r(&tmp_t, &tmp_tm);
668
668
  localtime_to_TIME(tmp, &tmp_tm);
669
 
  tmp->time_type= MYSQL_TIMESTAMP_DATETIME;
 
669
  tmp->time_type= DRIZZLE_TIMESTAMP_DATETIME;
670
670
}
671
671
 
672
672
 
689
689
/*
690
690
  Instance of this class represents UTC time zone. It uses system gmtime_r
691
691
  function for conversions and is always available. It is used only for
692
 
  my_time_t -> MYSQL_TIME conversions in various UTC_...  functions, it is not
693
 
  intended for MYSQL_TIME -> my_time_t conversions and shouldn't be exposed to user.
 
692
  my_time_t -> DRIZZLE_TIME conversions in various UTC_...  functions, it is not
 
693
  intended for DRIZZLE_TIME -> my_time_t conversions and shouldn't be exposed to user.
694
694
*/
695
695
class Time_zone_utc : public Time_zone
696
696
{
697
697
public:
698
698
  Time_zone_utc() {}                          /* Remove gcc warning */
699
 
  virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t,
 
699
  virtual my_time_t TIME_to_gmt_sec(const DRIZZLE_TIME *t,
700
700
                                    bool *in_dst_time_gap) const;
701
 
  virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const;
 
701
  virtual void gmt_sec_to_TIME(DRIZZLE_TIME *tmp, my_time_t t) const;
702
702
  virtual const String * get_name() const;
703
703
};
704
704
 
705
705
 
706
706
/*
707
 
  Convert UTC time from MYSQL_TIME representation to its my_time_t representation.
 
707
  Convert UTC time from DRIZZLE_TIME representation to its my_time_t representation.
708
708
 
709
709
  SYNOPSIS
710
710
    TIME_to_gmt_sec()
711
 
      t               - pointer to MYSQL_TIME structure with local time
 
711
      t               - pointer to DRIZZLE_TIME structure with local time
712
712
                        in broken-down representation.
713
713
      in_dst_time_gap - pointer to bool which is set to true if datetime
714
714
                        value passed doesn't really exist (i.e. falls into
723
723
    0
724
724
*/
725
725
my_time_t
726
 
Time_zone_utc::TIME_to_gmt_sec(const MYSQL_TIME *t __attribute__((unused)),
 
726
Time_zone_utc::TIME_to_gmt_sec(const DRIZZLE_TIME *t __attribute__((unused)),
727
727
                               bool *in_dst_time_gap __attribute__((unused))) const
728
728
{
729
729
  /* Should be never called */
738
738
 
739
739
  SYNOPSIS
740
740
    gmt_sec_to_TIME()
741
 
      tmp - pointer to MYSQL_TIME structure to fill-in
 
741
      tmp - pointer to DRIZZLE_TIME structure to fill-in
742
742
      t   - my_time_t value to be converted
743
743
 
744
744
  NOTE
745
745
    See note for apropriate Time_zone_system method.
746
746
*/
747
747
void
748
 
Time_zone_utc::gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const
 
748
Time_zone_utc::gmt_sec_to_TIME(DRIZZLE_TIME *tmp, my_time_t t) const
749
749
{
750
750
  struct tm tmp_tm;
751
751
  time_t tmp_t= (time_t)t;
752
752
  gmtime_r(&tmp_t, &tmp_tm);
753
753
  localtime_to_TIME(tmp, &tmp_tm);
754
 
  tmp->time_type= MYSQL_TIMESTAMP_DATETIME;
 
754
  tmp->time_type= DRIZZLE_TIMESTAMP_DATETIME;
755
755
}
756
756
 
757
757
 
786
786
{
787
787
public:
788
788
  Time_zone_db(TIME_ZONE_INFO *tz_info_arg, const String * tz_name_arg);
789
 
  virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t,
 
789
  virtual my_time_t TIME_to_gmt_sec(const DRIZZLE_TIME *t,
790
790
                                    bool *in_dst_time_gap) const;
791
 
  virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const;
 
791
  virtual void gmt_sec_to_TIME(DRIZZLE_TIME *tmp, my_time_t t) const;
792
792
  virtual const String * get_name() const;
793
793
private:
794
794
  TIME_ZONE_INFO *tz_info;
822
822
 
823
823
  SYNOPSIS
824
824
    TIME_to_gmt_sec()
825
 
      t               - pointer to MYSQL_TIME structure with local time
 
825
      t               - pointer to DRIZZLE_TIME structure with local time
826
826
                        in broken-down representation.
827
827
      in_dst_time_gap - pointer to bool which is set to true if datetime
828
828
                        value passed doesn't really exist (i.e. falls into
836
836
    Corresponding my_time_t value or 0 in case of error
837
837
*/
838
838
my_time_t
839
 
Time_zone_db::TIME_to_gmt_sec(const MYSQL_TIME *t, bool *in_dst_time_gap) const
 
839
Time_zone_db::TIME_to_gmt_sec(const DRIZZLE_TIME *t, bool *in_dst_time_gap) const
840
840
{
841
841
  return ::TIME_to_gmt_sec(t, tz_info, in_dst_time_gap);
842
842
}
848
848
 
849
849
  SYNOPSIS
850
850
    gmt_sec_to_TIME()
851
 
      tmp - pointer to MYSQL_TIME structure to fill-in
 
851
      tmp - pointer to DRIZZLE_TIME structure to fill-in
852
852
      t   - my_time_t value to be converted
853
853
*/
854
854
void
855
 
Time_zone_db::gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const
 
855
Time_zone_db::gmt_sec_to_TIME(DRIZZLE_TIME *tmp, my_time_t t) const
856
856
{
857
857
  ::gmt_sec_to_TIME(tmp, t, tz_info);
858
858
}
882
882
{
883
883
public:
884
884
  Time_zone_offset(long tz_offset_arg);
885
 
  virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t,
 
885
  virtual my_time_t TIME_to_gmt_sec(const DRIZZLE_TIME *t,
886
886
                                    bool *in_dst_time_gap) const;
887
 
  virtual void   gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const;
 
887
  virtual void   gmt_sec_to_TIME(DRIZZLE_TIME *tmp, my_time_t t) const;
888
888
  virtual const String * get_name() const;
889
889
  /*
890
890
    This have to be public because we want to be able to access it from
919
919
 
920
920
/*
921
921
  Converts local time in time zone described as offset from UTC
922
 
  from MYSQL_TIME representation to its my_time_t representation.
 
922
  from DRIZZLE_TIME representation to its my_time_t representation.
923
923
 
924
924
  SYNOPSIS
925
925
    TIME_to_gmt_sec()
926
 
      t               - pointer to MYSQL_TIME structure with local time
 
926
      t               - pointer to DRIZZLE_TIME structure with local time
927
927
                        in broken-down representation.
928
928
      in_dst_time_gap - pointer to bool which should be set to true if
929
929
                        datetime  value passed doesn't really exist
935
935
    Corresponding my_time_t value or 0 in case of error
936
936
*/
937
937
my_time_t
938
 
Time_zone_offset::TIME_to_gmt_sec(const MYSQL_TIME *t,
 
938
Time_zone_offset::TIME_to_gmt_sec(const DRIZZLE_TIME *t,
939
939
                                  bool *in_dst_time_gap __attribute__((unused))) const
940
940
{
941
941
  my_time_t local_t;
981
981
 
982
982
  SYNOPSIS
983
983
    gmt_sec_to_TIME()
984
 
      tmp - pointer to MYSQL_TIME structure to fill-in
 
984
      tmp - pointer to DRIZZLE_TIME structure to fill-in
985
985
      t   - my_time_t value to be converted
986
986
*/
987
987
void
988
 
Time_zone_offset::gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const
 
988
Time_zone_offset::gmt_sec_to_TIME(DRIZZLE_TIME *tmp, my_time_t t) const
989
989
{
990
990
  sec_to_TIME(tmp, t, offset);
991
991
}