n8n-nodes-lunar-calendar-vi
Version:
n8n community node để chuyển đổi âm lịch - dương lịch Việt Nam
247 lines • 10.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LunarCalendarVi = void 0;
const n8n_workflow_1 = require("n8n-workflow");
// Import thư viện lunar-date
const { SolarDate, LunarDate } = require("@nghiavuive/lunar_date_vi");
class LunarCalendarVi {
constructor() {
this.description = {
displayName: "Lunar Calendar VI",
name: "lunarCalendarVi",
icon: "file:lunarCalendar.svg",
group: ["transform"],
version: 1,
description: "Chuyển đổi giữa âm lịch và dương lịch Việt Nam",
defaults: {
name: "Lunar Calendar VI",
},
inputs: ["main" /* NodeConnectionType.Main */],
outputs: ["main" /* NodeConnectionType.Main */],
properties: [
{
displayName: "Thao tác",
name: "operation",
type: "options",
noDataExpression: true,
options: [
{
name: "Dương lịch sang Âm lịch",
value: "solarToLunar",
},
{
name: "Âm lịch sang Dương lịch",
value: "lunarToSolar",
},
],
default: "solarToLunar",
},
{
displayName: "Nguồn dữ liệu",
name: "dataSource",
type: "options",
options: [
{
name: "Ngày hiện tại",
value: "current",
},
{
name: "Ngày cụ thể",
value: "specific",
},
],
default: "current",
displayOptions: {
show: {
operation: ["solarToLunar"],
},
},
},
{
displayName: "Ngày",
name: "day",
type: "number",
default: 1,
displayOptions: {
show: {
operation: ["solarToLunar", "lunarToSolar"],
dataSource: ["specific"],
},
},
},
{
displayName: "Tháng",
name: "month",
type: "number",
default: 1,
displayOptions: {
show: {
operation: ["solarToLunar", "lunarToSolar"],
dataSource: ["specific"],
},
},
},
{
displayName: "Năm",
name: "year",
type: "number",
default: 2024,
displayOptions: {
show: {
operation: ["solarToLunar", "lunarToSolar"],
dataSource: ["specific"],
},
},
},
{
displayName: "Ngày âm lịch",
name: "lunarDay",
type: "number",
default: 1,
displayOptions: {
show: {
operation: ["lunarToSolar"],
},
},
},
{
displayName: "Tháng âm lịch",
name: "lunarMonth",
type: "number",
default: 1,
displayOptions: {
show: {
operation: ["lunarToSolar"],
},
},
},
{
displayName: "Năm âm lịch",
name: "lunarYear",
type: "number",
default: 2024,
displayOptions: {
show: {
operation: ["lunarToSolar"],
},
},
},
{
displayName: "Tháng nhuận",
name: "leapMonth",
type: "boolean",
default: false,
displayOptions: {
show: {
operation: ["lunarToSolar"],
},
},
},
],
};
}
async execute() {
var _a, _b, _c, _d, _e, _f;
const items = this.getInputData();
const returnData = [];
for (let i = 0; i < items.length; i++) {
try {
const operation = this.getNodeParameter("operation", i);
let result = {};
if (operation === "solarToLunar") {
const dataSource = this.getNodeParameter("dataSource", i);
let solarDate;
if (dataSource === "current") {
solarDate = new SolarDate(new Date());
}
else {
const day = this.getNodeParameter("day", i);
const month = this.getNodeParameter("month", i);
const year = this.getNodeParameter("year", i);
solarDate = new SolarDate(new Date(year, month - 1, day));
}
const lunarDate = solarDate.toLunarDate();
const solarInfo = solarDate.get();
const lunarInfo = lunarDate.get();
result = {
solar: {
day: solarInfo.day,
month: solarInfo.month,
year: solarInfo.year,
leap_year: solarInfo.leap_year,
},
lunar: {
day: lunarInfo.day,
month: lunarInfo.month,
year: lunarInfo.year,
leap_year: lunarInfo.leap_year,
leap_month: lunarInfo.leap_month,
year_name: ((_a = lunarDate.getYearName) === null || _a === void 0 ? void 0 : _a.call(lunarDate)) || "",
month_name: ((_b = lunarDate.getMonthName) === null || _b === void 0 ? void 0 : _b.call(lunarDate)) || "",
day_name: ((_c = lunarDate.getDayName) === null || _c === void 0 ? void 0 : _c.call(lunarDate)) || "",
},
julian: lunarInfo.julian,
};
}
else if (operation === "lunarToSolar") {
const day = this.getNodeParameter("lunarDay", i);
const month = this.getNodeParameter("lunarMonth", i);
const year = this.getNodeParameter("lunarYear", i);
const leapMonth = this.getNodeParameter("leapMonth", i);
const lunarDate = new LunarDate({
day,
month,
year,
leap_month: leapMonth,
});
lunarDate.init();
const solarDate = lunarDate.toSolarDate();
const solarInfo = solarDate.get();
const lunarInfo = lunarDate.get();
result = {
lunar: {
day: lunarInfo.day,
month: lunarInfo.month,
year: lunarInfo.year,
leap_year: lunarInfo.leap_year,
leap_month: lunarInfo.leap_month,
year_name: ((_d = lunarDate.getYearName) === null || _d === void 0 ? void 0 : _d.call(lunarDate)) || "",
month_name: ((_e = lunarDate.getMonthName) === null || _e === void 0 ? void 0 : _e.call(lunarDate)) || "",
day_name: ((_f = lunarDate.getDayName) === null || _f === void 0 ? void 0 : _f.call(lunarDate)) || "",
},
solar: {
day: solarInfo.day,
month: solarInfo.month,
year: solarInfo.year,
leap_year: solarInfo.leap_year,
date: new Date(solarInfo.year, solarInfo.month - 1, solarInfo.day),
},
julian: lunarInfo.julian,
};
}
returnData.push({
json: result,
pairedItem: i,
});
}
catch (error) {
if (this.continueOnFail()) {
returnData.push({
json: {
error: error.message,
},
pairedItem: i,
});
}
else {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, {
itemIndex: i,
});
}
}
}
return this.prepareOutputData(returnData);
}
}
exports.LunarCalendarVi = LunarCalendarVi;
//# sourceMappingURL=LunarCalendarVi.node.js.map