Node Script

Day Of the Week

Downloads: 24
Download
Ads Support FTD

Description

A Custom node script that gives you the day of the week in multiple formats:
Numeric (0–6, where 0 = Sunday)
Numeric (1–7, where 1 = Monday, 7 = Sunday)
Short name (e.g., “Mon”)
Long name (e.g., “Monday”)

@customNode()
export class DayOfWeek extends BasicScriptNode {
  @output()
  day0to6: number; // 0 = Sunday, 6 = Saturday
  @output()
  day1to7: number; // 1 = Monday, 7 = Sunday
  @output()
  shortName: string;
  @output()
  longName: string;

  private readonly SHORT_NAMES: string[] = [
    "Sun","Mon","Tue","Wed","Thu","Fri","Sat"
  ];

  private readonly LONG_NAMES: string[] = [
    "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"
  ];

  execute() {
    const today = new Date();
    const day = today.getDay(); // 0 = Sunday, 6 = Saturday

    this.day0to6 = day;
    this.day1to7 = day === 0 ? 7 : day;
    this.shortName = this.SHORT_NAMES[day];
    this.longName = this.LONG_NAMES[day];
  }
}
Ads Support FTD