~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_timefunc.cc

moving functions from item_timefunc to functions/time directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
890
890
  return (str != end);
891
891
}
892
892
 
893
 
int64_t Item_func_month::val_int()
894
 
{
895
 
  assert(fixed == 1);
896
 
  DRIZZLE_TIME ltime;
897
 
  (void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
898
 
  return (int64_t) ltime.month;
899
 
}
900
 
 
901
 
 
902
 
String* Item_func_monthname::val_str(String* str)
903
 
{
904
 
  assert(fixed == 1);
905
 
  const char *month_name;
906
 
  uint32_t   month= (uint) val_int();
907
 
  Session *session= current_session;
908
 
 
909
 
  if (null_value || !month)
910
 
  {
911
 
    null_value=1;
912
 
    return (String*) 0;
913
 
  }
914
 
  null_value=0;
915
 
  month_name= session->variables.lc_time_names->month_names->type_names[month-1];
916
 
  str->set(month_name, strlen(month_name), system_charset_info);
917
 
  return str;
918
 
}
919
 
 
920
 
 
921
 
/**
922
 
  Returns the quarter of the year.
923
 
*/
924
 
 
925
 
int64_t Item_func_quarter::val_int()
926
 
{
927
 
  assert(fixed == 1);
928
 
  DRIZZLE_TIME ltime;
929
 
  if (get_arg0_date(&ltime, TIME_FUZZY_DATE))
930
 
    return 0;
931
 
  return (int64_t) ((ltime.month+2)/3);
932
 
}
933
 
 
934
 
int64_t Item_func_hour::val_int()
935
 
{
936
 
  assert(fixed == 1);
937
 
  DRIZZLE_TIME ltime;
938
 
  (void) get_arg0_time(&ltime);
939
 
  return ltime.hour;
940
 
}
941
 
 
942
 
int64_t Item_func_minute::val_int()
943
 
{
944
 
  assert(fixed == 1);
945
 
  DRIZZLE_TIME ltime;
946
 
  (void) get_arg0_time(&ltime);
947
 
  return ltime.minute;
948
 
}
949
 
 
950
 
/**
951
 
  Returns the second in time_exp in the range of 0 - 59.
952
 
*/
953
 
int64_t Item_func_second::val_int()
954
 
{
955
 
  assert(fixed == 1);
956
 
  DRIZZLE_TIME ltime;
957
 
  (void) get_arg0_time(&ltime);
958
 
  return ltime.second;
959
 
}
960
 
 
961
 
 
962
 
uint32_t week_mode(uint32_t mode)
963
 
{
964
 
  uint32_t week_format= (mode & 7);
965
 
  if (!(week_format & WEEK_MONDAY_FIRST))
966
 
    week_format^= WEEK_FIRST_WEEKDAY;
967
 
  return week_format;
968
 
}
969
 
 
970
 
/**
971
 
 @verbatim
972
 
  The bits in week_format(for calc_week() function) has the following meaning:
973
 
   WEEK_MONDAY_FIRST (0)  If not set    Sunday is first day of week
974
 
                          If set        Monday is first day of week
975
 
   WEEK_YEAR (1)          If not set    Week is in range 0-53
976
 
 
977
 
        Week 0 is returned for the the last week of the previous year (for
978
 
        a date at start of january) In this case one can get 53 for the
979
 
        first week of next year.  This flag ensures that the week is
980
 
        relevant for the given year. Note that this flag is only
981
 
        releveant if WEEK_JANUARY is not set.
982
 
 
983
 
                          If set         Week is in range 1-53.
984
 
 
985
 
        In this case one may get week 53 for a date in January (when
986
 
        the week is that last week of previous year) and week 1 for a
987
 
        date in December.
988
 
 
989
 
  WEEK_FIRST_WEEKDAY (2)  If not set    Weeks are numbered according
990
 
                                        to ISO 8601:1988
991
 
                          If set        The week that contains the first
992
 
                                        'first-day-of-week' is week 1.
993
 
        
994
 
        ISO 8601:1988 means that if the week containing January 1 has
995
 
        four or more days in the new year, then it is week 1;
996
 
        Otherwise it is the last week of the previous year, and the
997
 
        next week is week 1.
998
 
 @endverbatim
999
 
*/
1000
 
 
1001
 
int64_t Item_func_week::val_int()
1002
 
{
1003
 
  assert(fixed == 1);
1004
 
  uint32_t year;
1005
 
  DRIZZLE_TIME ltime;
1006
 
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
1007
 
    return 0;
1008
 
  return (int64_t) calc_week(&ltime,
1009
 
                              week_mode((uint) args[1]->val_int()),
1010
 
                              &year);
1011
 
}
1012
 
 
1013
893
 
1014
894
int64_t Item_func_yearweek::val_int()
1015
895
{
1025
905
}
1026
906
 
1027
907
 
1028
 
int64_t Item_func_weekday::val_int()
1029
 
{
1030
 
  assert(fixed == 1);
1031
 
  DRIZZLE_TIME ltime;
1032
 
  
1033
 
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
1034
 
    return 0;
1035
 
 
1036
 
  return (int64_t) calc_weekday(calc_daynr(ltime.year, ltime.month,
1037
 
                                            ltime.day),
1038
 
                                 odbc_type) + test(odbc_type);
1039
 
}
1040
 
 
1041
 
 
1042
908
String* Item_func_dayname::val_str(String* str)
1043
909
{
1044
910
  assert(fixed == 1);