kettle创建日期维度表
程序员文章站
2022-03-31 19:16:33
...
一:流程
二:实现步骤
1.生成记录
2.增加日期序列
3.生成日期的属性(JavaScript代码)
//locale
var locale = new java.util.Locale(language.getString(),country.getString());
//calendar
var calendar = new java.util.GregorianCalendar(locale);
//设置时间
calendar.setTime(init_date.getDate());
//设置日历为当前日期
calendar.add(calendar.DAY_OF_MONTH,DaySequence.getInteger()-1);
//获取日期
var date = new java.util.Date(calendar.getTimeInMillis());
//短日期
var date_short = java.text.DateFormat.getDateInstance(java.text.DateFormat.SHORT,locale).format(date);
//中日期
var date_medium = java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM,locale).format(date);
//长日期
var date_long = java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG,locale).format(date);
//全日期
var date_full = java.text.DateFormat.getDateInstance(java.text.DateFormat.FULL,locale).format(date);
//简单格式化
var simpleDateFormat = java.text.SimpleDateFormat("D",locale);
//获取天在年中第几天
var day_in_year= simpleDateFormat.format(date);
//建立格式器
simpleDateFormat.applyPattern("d");
//获取天在月的第几天
var day_in_month = simpleDateFormat.format(date);
//星期格式器
simpleDateFormat.applyPattern("EEEE");
//获取星期名称
var day_name = simpleDateFormat.format(date);
//星期缩写格式器
simpleDateFormat.applyPattern("EEEE");
//获取星期名称
var day_name = simpleDateFormat.format(date);
//一年第几周的格式器
simpleDateFormat.applyPattern("ww");
//获取一年的第几周
var week_in_year = simpleDateFormat.format(date);
//月第几周的格式器
simpleDateFormat.applyPattern("W");
//获取月的第几周
var week_in_month = simpleDateFormat.format(date);
//月份
simpleDateFormat.applyPattern("MM");
//获取月份
var month_number = simpleDateFormat.format(date);
//月份名称
simpleDateFormat.applyPattern("MMMM");
//获取月的名称
var month_name = simpleDateFormat.format(date);
//月的缩写
simpleDateFormat.applyPattern("MMM");
//获取月的缩写
var month_abbreviation = simpleDateFormat.format(date);
//两位数年份
simpleDateFormat.applyPattern("yy");
//获取两位数年份
var year2 = simpleDateFormat.format(date);
//四位数年份
simpleDateFormat.applyPattern("yyyy");
//获取四位数年份
var year4 = simpleDateFormat.format(date);
//季度名称
var quarter_name = "Q";
//季度
var quarter_number;
switch(parseInt(month_number)){
case 1:
case 2:
case 3:
quarter_number = "1";
break;
case 4:
case 5:
case 6:
quarter_number = "2";
break;
case 7:
case 8:
case 9:
quarter_number = "3";
break;
case 10:
case 11:
case 12:
quarter_number = "4";
break;
}
quarter_name += quarter_number;
//定义常量,用于判断是否为周的第一天/最后一天
var yes = "Y";
var no = "N";
//获取周的第一天
var first_day_of_week = calendar.getFirstDayOfWeek();
var day_of_week = java.util.Calendar.DAY_OF_WEEK;
//判断是否为周的第一天
var is_first_day_of_week;
if(first_day_of_week == calendar.get(day_of_week)){
is_first_day_of_week = yes;
}else{
is_first_day_of_week = no;
}
//日历的下一天
calendar.add(calendar.DAY_OF_MONTH,1);
//获取下一天
var next_day = new java.util.Date(calendar.getTimeInMillis());
//判断是否为下一天
var is_last_day_of_week;
if(first_day_of_week == calendar.get(day_of_week)){
is_last_day_of_week = yes;
}else{
is_last_day_of_week = no;
}
//是否为月的第一天
var is_first_day_in_month;
if(day_in_month == 1){
is_first_day_in_month = yes;
}else{
is_first_day_in_month = no;
}
//是否为月的最后一天
var is_last_day_in_month;
if(java.text.SimpleDateFormat("d",locale).format(next_day) == 1){
is_last_day_in_month = yes;
}else{
is_last_day_in_month = no;
}
//年-季度
var year_quarter = year4 + "-" + quarter_name;
//年-月份
var year_month_number = year4+ "-" + month_number;
//年-月缩写
var year_month_abbreviation = year4 + "-" + month_abbreviation;
//日期代理键 , 唯一键
var day_key = year4 + month_number + (day_in_month < 10 ? "0" : "") + day_in_month;
4.表输出
5:目标表示例
上一篇: php max() min() 返回最大值和最小值
下一篇: Nginx场景应用技术分享