Kategori arşivi: Sap Lumira Designer

Sap BO Lumira Designer tarih fonksiyonları (date functions)

Sap BO Lumira Designer’da (eski adı Sap BO Design Studio) Date (DateObject) (UTC) veri tipi geldi. Global değişkenler (global variables) Date veri tipinde tanımlanamıyorlar, Date objesi kod bloğu içinde tanımlanabiliyor/kullanılabiliyor.

Date objesi createUTC ile oluşturulurken aylar 1-12 arasında değil 0-11 arasında tanımlanıyor.

Date objesinin getUTCDay fonksiyonu haftanın kaçıncı günü olduğunu döndürüyor. Dönüş değerleri 0-6 arasında, 0 Pazar, 6 Cumartesi.

Amaç içinde bulunulan haftanın ilk gününü (pazartesi) bulmak. İlk yöntem Date objesinin valueOf fonksiyonunu farketmeden önce yazdığım/geliştirdiğim yöntem. İkinci yöntem (doğru, kolay, kısa, olması gereken yöntem) valueOf fonksiyonu ile hesapladığım yöntem.

lumira_designer__date_functions__get_week_start__first_method.txt
lumira_designer__date_functions__get_week_start__second_method.txt

---------------------------------------
---------------------------------------

LIB_DATE.get_current_week_start()

var day_of_week_0 = [1,2,3,4,5,6];
var day_of_week_1 = [0];
day_of_week_1.pop();
var day_of_week_2 = [1];
var day_of_week_3 = [1,2];
var day_of_week_4 = [1,2,3];
var day_of_week_5 = [1,2,3,4];
var day_of_week_6 = [1,2,3,4,5];
var day_of_week_temp = [0];
day_of_week_temp.pop();

var lv_today_YYYYMMDD = APPLICATION.getInfo().dateNowInternalFormat;

var lv_year_YYYY = Convert.subString(lv_today_YYYYMMDD, 0, 4);
var lv_month_MM = Convert.subString(lv_today_YYYYMMDD, 4, 6);
var lv_day_DD = Convert.subString(lv_today_YYYYMMDD, 6, 8);

var lv_year_int_YYYY = Convert.stringToInt(lv_year_YYYY);
var lv_month_int_MM = Convert.stringToInt(lv_month_MM);
var lv_day_int_DD = Convert.stringToInt(lv_day_DD);

var lv_today_DATE = Date.createUTC(lv_year_int_YYYY, lv_month_int_MM-1, lv_day_int_DD); // UTC months 0-11

if ( lv_today_DATE.getUTCDay() == 1 ) { // 0-6 Monday
	day_of_week_temp = day_of_week_1;
} else if ( lv_today_DATE.getUTCDay() == 2 ) { // 0-6 Tuesday
	day_of_week_temp = day_of_week_2;
} else if ( lv_today_DATE.getUTCDay() == 3 ) { // 0-6 Wednesday
	day_of_week_temp = day_of_week_3;
} else if ( lv_today_DATE.getUTCDay() == 4 ) { // 0-6 Thursday
	day_of_week_temp = day_of_week_4;
} else if ( lv_today_DATE.getUTCDay() == 5 ) { // 0-6 Friday
	day_of_week_temp = day_of_week_5;
} else if ( lv_today_DATE.getUTCDay() == 6 ) { // 0-6 Saturday
	day_of_week_temp = day_of_week_6;
} else if ( lv_today_DATE.getUTCDay() == 0 ) { // 0-6 Sunday
	day_of_week_temp = day_of_week_0;
}
day_of_week_temp.forEach(function(elm, ind) {
	lv_today_YYYYMMDD = LIB_DATE.get_previous_day(lv_today_YYYYMMDD);
});

var lv_current_week_start_YYYYMMDD = lv_today_YYYYMMDD;

return lv_current_week_start_YYYYMMDD;

---------------------------------------
---------------------------------------

LIB_DATE.get_previous_day(p_date(String))

var lv_today_YYYYMMDD = p_date;

var lv_year_YYYY = Convert.subString(lv_today_YYYYMMDD, 0, 4);
var lv_month_MM = Convert.subString(lv_today_YYYYMMDD, 4, 6);
var lv_day_DD = Convert.subString(lv_today_YYYYMMDD, 6, 8);

var lv_year_int = Convert.stringToInt(lv_year_YYYY);
var lv_month_int = Convert.stringToInt(lv_month_MM);
var lv_day_int = Convert.stringToInt(lv_day_DD);

var lv_previous_day = "";

if (lv_day_int != 1) {
	lv_previous_day = lv_year_YYYY + lv_month_MM + LIB_DATE.get_two_digit_month_or_day(lv_day_int-1);
} else {
	if (lv_month_int != 1) { // go previous month
		lv_previous_day = lv_year_YYYY + LIB_DATE.get_two_digit_month_or_day(lv_month_int-1) + LIB_DATE.get_two_digit_month_or_day(LIB_DATE.get_previous_month_days(p_date));
	} else { // go previous month and year
		lv_previous_day = Convert.floatToString(lv_year_int-1,"###0") + LIB_DATE.get_two_digit_month_or_day(12) + LIB_DATE.get_two_digit_month_or_day(LIB_DATE.get_previous_month_days(p_date));
	}
}

return lv_previous_day;

---------------------------------------
---------------------------------------

LIB_DATE.get_previous_month_days(p_date(String))

var lv_previous_month_start_YYYYMMDD = LIB_DATE.get_previous_month_start(p_date);

var lv_year_YYYY = Convert.subString(lv_previous_month_start_YYYYMMDD, 0, 4);
var lv_month_MM = Convert.subString(lv_previous_month_start_YYYYMMDD, 4, 6);
var lv_day_DD = Convert.subString(lv_previous_month_start_YYYYMMDD, 6, 8);

var lv_year_int_YYYY = Convert.stringToInt(lv_year_YYYY);
var lv_month_int_MM = Convert.stringToInt(lv_month_MM);
var lv_day_int_DD = Convert.stringToInt(lv_day_DD);

var lv_previous_month_days = 0;

if (lv_month_MM=="01" || lv_month_MM=="03" || lv_month_MM=="05" || lv_month_MM=="07" || lv_month_MM=="08" || lv_month_MM=="10" || lv_month_MM=="12") {
	lv_previous_month_days = 31;
} else if (lv_month_MM=="04" || lv_month_MM=="06" || lv_month_MM=="09" || lv_month_MM=="11") {
	lv_previous_month_days = 30;
} else  if (lv_month_MM=="02") {
	if ( Math.floor(lv_year_int_YYYY/4)*4 == lv_year_int_YYYY ) {
		// leap year
		lv_previous_month_days = 29;
	} else {
		lv_previous_month_days = 28;
	}
}

return lv_previous_month_days;

---------------------------------------
---------------------------------------

LIB_DATE.get_today()

return APPLICATION.getInfo().dateNowInternalFormat;

---------------------------------------
---------------------------------------

LIB_DATE.get_two_digit_month_or_day(p_day_or_month(int))

if (p_day_or_month < 10) {
	return "0"+Convert.floatToString(p_day_or_month,"#0");
} else {
	return Convert.floatToString(p_day_or_month,"#0");
}

---------------------------------------
---------------------------------------

LIB_DATE.get_week_start(p_date(String))

var day_of_week_0 = [1,2,3,4,5,6];
var day_of_week_1 = [0];
day_of_week_1.pop();
var day_of_week_2 = [1];
var day_of_week_3 = [1,2];
var day_of_week_4 = [1,2,3];
var day_of_week_5 = [1,2,3,4];
var day_of_week_6 = [1,2,3,4,5];
var day_of_week_temp = [0];
day_of_week_temp.pop();

var lv_today_YYYYMMDD = p_date;

var lv_year_YYYY = Convert.subString(lv_today_YYYYMMDD, 0, 4);
var lv_month_MM = Convert.subString(lv_today_YYYYMMDD, 4, 6);
var lv_day_DD = Convert.subString(lv_today_YYYYMMDD, 6, 8);

var lv_year_int_YYYY = Convert.stringToInt(lv_year_YYYY);
var lv_month_int_MM = Convert.stringToInt(lv_month_MM);
var lv_day_int_DD = Convert.stringToInt(lv_day_DD);

var lv_today_DATE = Date.createUTC(lv_year_int_YYYY, lv_month_int_MM-1, lv_day_int_DD); // UTC months 0-11

if ( lv_today_DATE.getUTCDay() == 1 ) { // 0-6 Monday
	day_of_week_temp = day_of_week_1;
} else if ( lv_today_DATE.getUTCDay() == 2 ) { // 0-6 Tuesday
	day_of_week_temp = day_of_week_2;
} else if ( lv_today_DATE.getUTCDay() == 3 ) { // 0-6 Wednesday
	day_of_week_temp = day_of_week_3;
} else if ( lv_today_DATE.getUTCDay() == 4 ) { // 0-6 Thursday
	day_of_week_temp = day_of_week_4;
} else if ( lv_today_DATE.getUTCDay() == 5 ) { // 0-6 Friday
	day_of_week_temp = day_of_week_5;
} else if ( lv_today_DATE.getUTCDay() == 6 ) { // 0-6 Saturday
	day_of_week_temp = day_of_week_6;
} else if ( lv_today_DATE.getUTCDay() == 0 ) { // 0-6 Sunday
	day_of_week_temp = day_of_week_0;
}
day_of_week_temp.forEach(function(elm, ind) {
	lv_today_YYYYMMDD = LIB_DATE.get_previous_day(lv_today_YYYYMMDD);
});

var lv_week_start_YYYYMMDD = lv_today_YYYYMMDD;

return lv_week_start_YYYYMMDD;

---------------------------------------
---------------------------------------
---------------------------------------
---------------------------------------

LIB_DATE.get_current_week_start_2()

var lv_today_YYYYMMDD = APPLICATION.getInfo().dateNowInternalFormat;

var lv_year_YYYY = Convert.subString(lv_today_YYYYMMDD, 0, 4);
var lv_month_MM = Convert.subString(lv_today_YYYYMMDD, 4, 6);
var lv_day_DD = Convert.subString(lv_today_YYYYMMDD, 6, 8);

var lv_year_int_YYYY = Convert.stringToInt(lv_year_YYYY);
var lv_month_int_MM = Convert.stringToInt(lv_month_MM);
var lv_day_int_DD = Convert.stringToInt(lv_day_DD);

var lv_today_DATE = Date.createUTC(lv_year_int_YYYY, lv_month_int_MM-1, lv_day_int_DD); // UTC months 0-11

var lv_current_week_start_YYYYMMDD = "";

if ( lv_today_DATE.getUTCDay() == 1 ) { // 0-6 Monday
	lv_current_week_start_YYYYMMDD = LIB_DATE.get_relative_date(lv_today_YYYYMMDD,0);
} else if ( lv_today_DATE.getUTCDay() == 2 ) { // 0-6 Tuesday
	lv_current_week_start_YYYYMMDD = LIB_DATE.get_relative_date(lv_today_YYYYMMDD,-1);
} else if ( lv_today_DATE.getUTCDay() == 3 ) { // 0-6 Wednesday
	lv_current_week_start_YYYYMMDD = LIB_DATE.get_relative_date(lv_today_YYYYMMDD,-2);
} else if ( lv_today_DATE.getUTCDay() == 4 ) { // 0-6 Thursday
	lv_current_week_start_YYYYMMDD = LIB_DATE.get_relative_date(lv_today_YYYYMMDD,-3);
} else if ( lv_today_DATE.getUTCDay() == 5 ) { // 0-6 Friday
	lv_current_week_start_YYYYMMDD = LIB_DATE.get_relative_date(lv_today_YYYYMMDD,-4);
} else if ( lv_today_DATE.getUTCDay() == 6 ) { // 0-6 Saturday
	lv_current_week_start_YYYYMMDD = LIB_DATE.get_relative_date(lv_today_YYYYMMDD,-5);
} else if ( lv_today_DATE.getUTCDay() == 0 ) { // 0-6 Sunday
	lv_current_week_start_YYYYMMDD = LIB_DATE.get_relative_date(lv_today_YYYYMMDD,-6);
}

return lv_current_week_start_YYYYMMDD;

---------------------------------------
---------------------------------------

LIB_DATE.get_relative_date(p_date(String),p_n(int))

var lv_today_YYYYMMDD = p_date;

var lv_year_YYYY = Convert.subString(lv_today_YYYYMMDD, 0, 4);
var lv_month_MM = Convert.subString(lv_today_YYYYMMDD, 4, 6);
var lv_day_DD = Convert.subString(lv_today_YYYYMMDD, 6, 8);

var lv_year_int_YYYY = Convert.stringToInt(lv_year_YYYY);
var lv_month_int_MM = Convert.stringToInt(lv_month_MM);
var lv_day_int_DD = Convert.stringToInt(lv_day_DD);

var lv_today_DATE = Date.createUTC(lv_year_int_YYYY, lv_month_int_MM-1, lv_day_int_DD); // UTC months 0-11

var lv_today_utc_value = lv_today_DATE.valueOf();

var lv_relative_utc_value = lv_today_utc_value + (p_n * 24 * 60 * 60 * 1000);

var lv_relative_date_DATE = Date.createUTC(1970, 0, 1, 0, 0, 0, lv_relative_utc_value);

var lv_relative_date_YYYYMMDD = lv_relative_date_DATE.toSapDateString();

return lv_relative_date_YYYYMMDD;

---------------------------------------
---------------------------------------

LIB_DATE.get_today()

return APPLICATION.getInfo().dateNowInternalFormat;

---------------------------------------
---------------------------------------

LIB_DATE.get_two_digit_month_or_day(p_day_or_month(int))

if (p_day_or_month < 10) {
	return "0"+Convert.floatToString(p_day_or_month,"#0");
} else {
	return Convert.floatToString(p_day_or_month,"#0");
}

---------------------------------------
---------------------------------------

LIB_DATE.get_week_start_2(p_date(String))

var lv_today_YYYYMMDD = p_date;

var lv_year_YYYY = Convert.subString(lv_today_YYYYMMDD, 0, 4);
var lv_month_MM = Convert.subString(lv_today_YYYYMMDD, 4, 6);
var lv_day_DD = Convert.subString(lv_today_YYYYMMDD, 6, 8);

var lv_year_int_YYYY = Convert.stringToInt(lv_year_YYYY);
var lv_month_int_MM = Convert.stringToInt(lv_month_MM);
var lv_day_int_DD = Convert.stringToInt(lv_day_DD);

var lv_today_DATE = Date.createUTC(lv_year_int_YYYY, lv_month_int_MM-1, lv_day_int_DD); // UTC months 0-11

var lv_current_week_start_YYYYMMDD = "";

if ( lv_today_DATE.getUTCDay() == 1 ) { // 0-6 Monday
	lv_current_week_start_YYYYMMDD = LIB_DATE.get_relative_date(lv_today_YYYYMMDD,0);
} else if ( lv_today_DATE.getUTCDay() == 2 ) { // 0-6 Tuesday
	lv_current_week_start_YYYYMMDD = LIB_DATE.get_relative_date(lv_today_YYYYMMDD,-1);
} else if ( lv_today_DATE.getUTCDay() == 3 ) { // 0-6 Wednesday
	lv_current_week_start_YYYYMMDD = LIB_DATE.get_relative_date(lv_today_YYYYMMDD,-2);
} else if ( lv_today_DATE.getUTCDay() == 4 ) { // 0-6 Thursday
	lv_current_week_start_YYYYMMDD = LIB_DATE.get_relative_date(lv_today_YYYYMMDD,-3);
} else if ( lv_today_DATE.getUTCDay() == 5 ) { // 0-6 Friday
	lv_current_week_start_YYYYMMDD = LIB_DATE.get_relative_date(lv_today_YYYYMMDD,-4);
} else if ( lv_today_DATE.getUTCDay() == 6 ) { // 0-6 Saturday
	lv_current_week_start_YYYYMMDD = LIB_DATE.get_relative_date(lv_today_YYYYMMDD,-5);
} else if ( lv_today_DATE.getUTCDay() == 0 ) { // 0-6 Sunday
	lv_current_week_start_YYYYMMDD = LIB_DATE.get_relative_date(lv_today_YYYYMMDD,-6);
}

return lv_current_week_start_YYYYMMDD;

---------------------------------------
---------------------------------------