~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/tztime.cc

  • Committer: Monty Taylor
  • Date: 2008-08-02 01:03:15 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080802010315-65h5938pymg9d99z
Moved m4 macros to top-level m4 dir, per GNU standards (and where gettext wanted it :)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#pragma implementation                          // gcc: Class implementation
18
18
#endif
19
19
 
20
 
#include <my_global.h>
21
20
#include "mysql_priv.h"
22
 
#include <my_time.h>
 
21
#include <libdrizzle/my_time.h>
23
22
 
24
23
#include "tzfile.h"
25
 
#include <m_string.h>
26
24
 
27
25
/* Structure describing local time type (e.g. Moscow summer time (MSD)) */
28
26
typedef struct ttinfo
45
43
 
46
44
/*
47
45
  Structure with information describing ranges of my_time_t shifted to local
48
 
  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.
49
47
  See comments for TIME_to_gmt_sec() for more info.
50
48
*/
51
49
typedef struct revtinfo
132
130
      offset - local time zone offset
133
131
 
134
132
  DESCRIPTION
135
 
    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
136
134
    (from elsie code) because doesn't contain any leap correction and
137
135
    TM_GMTOFF and is_dst setting and contains some MySQL specific
138
136
    initialization. Funny but with removing of these we almost have
139
137
    glibc's offtime function.
140
138
*/
141
139
static void
142
 
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)
143
141
{
144
142
  long days;
145
143
  long rem;
195
193
  tmp->month++;
196
194
  tmp->day= (uint)(days + 1);
197
195
 
198
 
  /* filling MySQL specific MYSQL_TIME members */
 
196
  /* filling MySQL specific DRIZZLE_TIME members */
199
197
  tmp->neg= 0; tmp->second_part= 0;
200
 
  tmp->time_type= MYSQL_TIMESTAMP_DATETIME;
 
198
  tmp->time_type= DRIZZLE_TIMESTAMP_DATETIME;
201
199
}
202
200
 
203
201
 
287
285
 
288
286
/*
289
287
  Converts time in my_time_t representation (seconds in UTC since Epoch) to
290
 
  broken down MYSQL_TIME representation in local time zone.
 
288
  broken down DRIZZLE_TIME representation in local time zone.
291
289
 
292
290
  SYNOPSIS
293
291
    gmt_sec_to_TIME()
302
300
    (60th and 61st second, look how we calculate them as "hit" in this
303
301
    function).
304
302
    Under realistic assumptions about frequency of transitions the same array
305
 
    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
306
304
    implement tweaked binary search which will take into account that some
307
 
    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.
308
306
*/
309
307
static void
310
 
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)
311
309
{
312
310
  const TRAN_TYPE_INFO *ttisp;
313
311
  const LS_INFO *lp;
409
407
}
410
408
 
411
409
/*
412
 
  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
413
411
  representation.
414
412
 
415
413
  SYNOPSIS
451
449
 
452
450
    We use completely different approach. It is better since it is both
453
451
    faster than iterative implementations and fully determenistic. If you
454
 
    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
455
453
    of two steps:
456
454
    The first is calculating shifted my_time_t value and the second - TIME
457
455
    calculation from shifted my_time_t value (well it is a bit simplified
481
479
    0 in case of error.
482
480
*/
483
481
static my_time_t
484
 
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,
485
483
                bool *in_dst_time_gap)
486
484
{
487
485
  my_time_t local_t;
604
602
{
605
603
public:
606
604
  Time_zone_system() {}                       /* Remove gcc warning */
607
 
  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,
608
606
                                    bool *in_dst_time_gap) const;
609
 
  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;
610
608
  virtual const String * get_name() const;
611
609
};
612
610
 
613
611
 
614
612
/*
615
 
  Converts local time in system time zone in MYSQL_TIME representation
 
613
  Converts local time in system time zone in DRIZZLE_TIME representation
616
614
  to its my_time_t representation.
617
615
 
618
616
  SYNOPSIS
619
617
    TIME_to_gmt_sec()
620
 
      t               - pointer to MYSQL_TIME structure with local time in
 
618
      t               - pointer to DRIZZLE_TIME structure with local time in
621
619
                        broken-down representation.
622
620
      in_dst_time_gap - pointer to bool which is set to true if datetime
623
621
                        value passed doesn't really exist (i.e. falls into
625
623
 
626
624
  DESCRIPTION
627
625
    This method uses system function (localtime_r()) for conversion
628
 
    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
629
627
    representation. Unlike the same function for Time_zone_db class
630
628
    it it won't handle unnormalized input properly. Still it will
631
629
    return lowest possible my_time_t in case of ambiguity or if we
637
635
    Corresponding my_time_t value or 0 in case of error
638
636
*/
639
637
my_time_t
640
 
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
641
639
{
642
640
  long not_used;
643
641
  return my_system_gmt_sec(t, &not_used, in_dst_time_gap);
650
648
 
651
649
  SYNOPSIS
652
650
    gmt_sec_to_TIME()
653
 
      tmp - pointer to MYSQL_TIME structure to fill-in
 
651
      tmp - pointer to DRIZZLE_TIME structure to fill-in
654
652
      t   - my_time_t value to be converted
655
653
 
656
654
  NOTE
661
659
    the 1902 easily.
662
660
*/
663
661
void
664
 
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
665
663
{
666
664
  struct tm tmp_tm;
667
665
  time_t tmp_t= (time_t)t;
668
666
 
669
667
  localtime_r(&tmp_t, &tmp_tm);
670
668
  localtime_to_TIME(tmp, &tmp_tm);
671
 
  tmp->time_type= MYSQL_TIMESTAMP_DATETIME;
 
669
  tmp->time_type= DRIZZLE_TIMESTAMP_DATETIME;
672
670
}
673
671
 
674
672
 
691
689
/*
692
690
  Instance of this class represents UTC time zone. It uses system gmtime_r
693
691
  function for conversions and is always available. It is used only for
694
 
  my_time_t -> MYSQL_TIME conversions in various UTC_...  functions, it is not
695
 
  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.
696
694
*/
697
695
class Time_zone_utc : public Time_zone
698
696
{
699
697
public:
700
698
  Time_zone_utc() {}                          /* Remove gcc warning */
701
 
  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,
702
700
                                    bool *in_dst_time_gap) const;
703
 
  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;
704
702
  virtual const String * get_name() const;
705
703
};
706
704
 
707
705
 
708
706
/*
709
 
  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.
710
708
 
711
709
  SYNOPSIS
712
710
    TIME_to_gmt_sec()
713
 
      t               - pointer to MYSQL_TIME structure with local time
 
711
      t               - pointer to DRIZZLE_TIME structure with local time
714
712
                        in broken-down representation.
715
713
      in_dst_time_gap - pointer to bool which is set to true if datetime
716
714
                        value passed doesn't really exist (i.e. falls into
725
723
    0
726
724
*/
727
725
my_time_t
728
 
Time_zone_utc::TIME_to_gmt_sec(const MYSQL_TIME *t __attribute__((__unused__)),
729
 
                               bool *in_dst_time_gap __attribute__((__unused__))) const
 
726
Time_zone_utc::TIME_to_gmt_sec(const DRIZZLE_TIME *t __attribute__((unused)),
 
727
                               bool *in_dst_time_gap __attribute__((unused))) const
730
728
{
731
729
  /* Should be never called */
732
730
  assert(0);
740
738
 
741
739
  SYNOPSIS
742
740
    gmt_sec_to_TIME()
743
 
      tmp - pointer to MYSQL_TIME structure to fill-in
 
741
      tmp - pointer to DRIZZLE_TIME structure to fill-in
744
742
      t   - my_time_t value to be converted
745
743
 
746
744
  NOTE
747
745
    See note for apropriate Time_zone_system method.
748
746
*/
749
747
void
750
 
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
751
749
{
752
750
  struct tm tmp_tm;
753
751
  time_t tmp_t= (time_t)t;
754
752
  gmtime_r(&tmp_t, &tmp_tm);
755
753
  localtime_to_TIME(tmp, &tmp_tm);
756
 
  tmp->time_type= MYSQL_TIMESTAMP_DATETIME;
 
754
  tmp->time_type= DRIZZLE_TIMESTAMP_DATETIME;
757
755
}
758
756
 
759
757
 
788
786
{
789
787
public:
790
788
  Time_zone_db(TIME_ZONE_INFO *tz_info_arg, const String * tz_name_arg);
791
 
  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,
792
790
                                    bool *in_dst_time_gap) const;
793
 
  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;
794
792
  virtual const String * get_name() const;
795
793
private:
796
794
  TIME_ZONE_INFO *tz_info;
824
822
 
825
823
  SYNOPSIS
826
824
    TIME_to_gmt_sec()
827
 
      t               - pointer to MYSQL_TIME structure with local time
 
825
      t               - pointer to DRIZZLE_TIME structure with local time
828
826
                        in broken-down representation.
829
827
      in_dst_time_gap - pointer to bool which is set to true if datetime
830
828
                        value passed doesn't really exist (i.e. falls into
838
836
    Corresponding my_time_t value or 0 in case of error
839
837
*/
840
838
my_time_t
841
 
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
842
840
{
843
841
  return ::TIME_to_gmt_sec(t, tz_info, in_dst_time_gap);
844
842
}
850
848
 
851
849
  SYNOPSIS
852
850
    gmt_sec_to_TIME()
853
 
      tmp - pointer to MYSQL_TIME structure to fill-in
 
851
      tmp - pointer to DRIZZLE_TIME structure to fill-in
854
852
      t   - my_time_t value to be converted
855
853
*/
856
854
void
857
 
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
858
856
{
859
857
  ::gmt_sec_to_TIME(tmp, t, tz_info);
860
858
}
884
882
{
885
883
public:
886
884
  Time_zone_offset(long tz_offset_arg);
887
 
  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,
888
886
                                    bool *in_dst_time_gap) const;
889
 
  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;
890
888
  virtual const String * get_name() const;
891
889
  /*
892
890
    This have to be public because we want to be able to access it from
921
919
 
922
920
/*
923
921
  Converts local time in time zone described as offset from UTC
924
 
  from MYSQL_TIME representation to its my_time_t representation.
 
922
  from DRIZZLE_TIME representation to its my_time_t representation.
925
923
 
926
924
  SYNOPSIS
927
925
    TIME_to_gmt_sec()
928
 
      t               - pointer to MYSQL_TIME structure with local time
 
926
      t               - pointer to DRIZZLE_TIME structure with local time
929
927
                        in broken-down representation.
930
928
      in_dst_time_gap - pointer to bool which should be set to true if
931
929
                        datetime  value passed doesn't really exist
937
935
    Corresponding my_time_t value or 0 in case of error
938
936
*/
939
937
my_time_t
940
 
Time_zone_offset::TIME_to_gmt_sec(const MYSQL_TIME *t,
941
 
                                  bool *in_dst_time_gap __attribute__((__unused__))) const
 
938
Time_zone_offset::TIME_to_gmt_sec(const DRIZZLE_TIME *t,
 
939
                                  bool *in_dst_time_gap __attribute__((unused))) const
942
940
{
943
941
  my_time_t local_t;
944
942
  int shift= 0;
983
981
 
984
982
  SYNOPSIS
985
983
    gmt_sec_to_TIME()
986
 
      tmp - pointer to MYSQL_TIME structure to fill-in
 
984
      tmp - pointer to DRIZZLE_TIME structure to fill-in
987
985
      t   - my_time_t value to be converted
988
986
*/
989
987
void
990
 
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
991
989
{
992
990
  sec_to_TIME(tmp, t, offset);
993
991
}
1052
1050
*/
1053
1051
bool
1054
1052
my_tz_init(THD *thd, const char *default_tzname,
1055
 
           bool bootstrap __attribute__((__unused__)))
 
1053
           bool bootstrap __attribute__((unused)))
1056
1054
{
1057
1055
  if (default_tzname)
1058
1056
  {
1170
1168
 
1171
1169
*/
1172
1170
Time_zone *
1173
 
my_tz_find(THD *thd __attribute__((__unused__)),
1174
 
           const String *name __attribute__((__unused__)))
 
1171
my_tz_find(THD *thd __attribute__((unused)),
 
1172
           const String *name __attribute__((unused)))
1175
1173
{
1176
1174
  return NULL;
1177
1175
}