Query the first (or second etc) Sunday of the month

Hello!!
I must say I’m enjoying a lot Tinderbox. The variety of paths I can make are endless!
I have two questions related to dates:

  1. Is there any way I can make a rule to change the name of some $String if a date is the first Saturday of the month?
  2. How could I chance the language of the date string (Like $StartDate.format(W) appear in my language)?
    Tks
    Rafael

#1. If the first Saturday of the month, the second Saturday would be day #8 , and that the first seven days of the moth must contain one Saturary. Therefore we know the day of the month Date.day must be less than ‘8’. From Date.weekday() we know a Saturday is always value ‘6’. Putting this together, and using $StartDate as an example Date-type attribute & $MyString as a String-type target:

if($StartDate.weekday==6 & $StartDate.day<8) {
   $MyString="StartDate holds the first Saturday of the month";
}else{
   $MyString=;
}

The line breaks are for clarity only and have no effect on the code.

#2. The date format string “W” should give you the full name of the weekday. On my ‘en-UK’ locale system (i.e. British settings) date("today").format("W") returns Monday. As many parts of Tinderbox now respect the users locale setting I would expect the the day to be returned in your Mac’s normal language. Of course if you are working in one language but have the OS set to use another locale, that won’t work.

So, for #2, what you you expect to see, and what do you get using .format("W")?

Tks for both answers!

#2: I get the result in English, although the language in my macOS is Portuguese-BR.

Try date format “L” or “l”.

Still English
17 August 2020

Ah, OK. It looks like date.weekday() isn’t locale compliant. But, you could get around that by using a look-up table.

First I make a note “lDays”. The lowercase ‘l’-prefix is to remind me this is a look-up table note and give it a tilte i’m not likely to re-use for another note. the exact name doesn’t matter as long as later code looks up the right note! In this note’s $MyList, i add this loo-up table:

1:Segunda-feira;2:Terça-feira;3:Quarta-feira;4:Quinta-feira;5:Sexta-feira;6:Sábado;&:Domingo

The numbers aren’t a sequence but values returned by .weekday. Now i make a new note (tiytle doesn’t matter) and give it Key Attributes of $MString and $MyDate so we can see if thinks work. I set $MyDate to ‘today’ (17 August 2020 for later readers of the thread) and I add a stamp:

$MyString = $MyList("lDays").lookup($MyDate.weekday);

As today is Monday here in England we’d expect $MyDate.weekday to return a value of 11. The stamp then fetches the $MyList value for the lDays’ note, which has the day number-to day name lookup table. The result is that $MyString is “Segunda-feira” which is Monday in Portuguese, if google is to be believed! You could do the same for month names as well, by copying the same general model.

Noters:

  • You only need a single copy if the look up table so put the note in a safe corner of your document and give it a title ($Name) you will not then use for something else.
  • If you are going to look at $MyList across the whole document for some action code reason, you could give this it’s own attribute $DayList so nothing else uses that attribute name.
  • If you do the latter you could have a $DayList and $MonthList and have one note store both look-up tables.

That worked really well

Thank you very much!!!

1 Like

The formatter uses the date set by your current locale. If your Mac is set to use English, it will use English; if your Mac is set for Portuguese, it will use Portuguese.

Actions can change the locale. For example:

locale(“pt_PT”); $MyString=$StartDate.format("W"); locale();

sets $MyString to “segunda-feira”.

1 Like