summaryrefslogtreecommitdiff
path: root/macros/context/contrib/context-calendar-examples/tex/context/third/calendar-examples/Sundata-calendar.tex
blob: 18726204cb69c9c8d87142d0f73adc04e5738458 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
% Context file
% Filename: Sundata-calendar.tex
% 
% 13-07-2022
% Copyright (c) 2022 BOEDE. All rights reserved.
%
% \nopdfcompression
% \enabletrackers[context.trace]
% \enabletrackers[system.jobfiles]

\usemodule[pocketdiary]
\usemodule[collatingmarks][Collatingmarks=yes]

\definemode[English,Dutch,German,French,Italian,Spanish][keep]

\enablemode[English]
% \enablemode[German]
% \enablemode[Dutch]
% \enablemode[Italian]
% \enablemode[French]
%\enablemode[Spanish]

\setvariables
  [PocketDiary]
  [Year=2023,
   Week=1,
   Day=1,
   Month=1,
   Nextyear=no,
   Place=Sambeek,
   Country=NL]

\setvariables
  [PocketDiaryFooter]
  [Lefttext={\jobname .pdf},
   Centertext=\pagenumber,
   Righttext=]

\setvariables
  [PocketDiaryColors]
  [Separatorline=blue,
   Gridline={s=.75}]

\setvariables %Koziegłowy 52.467860,16.981240 //52.5921425,6.0962685,  % Hasselt
  [PocketDiaryGeoPosition]
  [lat=51.63682, %Sambeek Maasstraat 2A (Google Maps)
   lon=5.96655,  %Sambeek, Maasstraat 2A (Google Maps)
   timezoneoffset=1,
   continent=EU] %EU, US or empty for no DST

\setupbodyfont[ibmplex,ss,10pt]
% \usetypescriptfile[type-seravek]
% \usetypescript[Seravek]
% \setupbodyfont[Seravek,ss,10pt]

% Modes for the international interface

\startmode[English]
  \mainlanguage[en]
\stopmode

\startmode[Dutch]
  \mainlanguage[nl]
\stopmode

\startmode[German]
  \mainlanguage[de]
\stopmode

\startmode[French]
  \mainlanguage[fr]
\stopmdode

\startmode[Italian]
  \mainlanguage[it]
\stopmode

\startmode[Spanish]
  \mainlanguage[es]
\stopmode

\setuppagenumbering[alternative=doublesided,location=]

\setuppapersize[A6][A6]

\setuplayout
  [topspace=.6cm,
   backspace=.6cm,
   header=2\bodyfontsize,
   headerdistance=.5\bodyfontsize,
   footer=1.2\bodyfontsize,
   footerdistance=.5\bodyfontsize,
   margin=0pt,
   height=middle,
   width=88mm,
   location=middle]

\setuparranging[2*4*2]

\setupMPvariables % for collatingmarks
   [pages=8,  % pages per sheet of paper doublesided
    sheets=2,  % sheets of paper used per section
    horpageshift=0mm]

\startluacode

local report = logs.reporter("Sundata calendar")

function thirddata.diary.year_of_monthtables(
  year,lat,lon,timeoffset,continent)

  report("Working in function: diary.year_of_monthtables")

  local dst_start,dst_stop = thirddata.diary.DST(year,continent)

  report("DST start: %s, DST stop: %s",dst_start,dst_stop)

  for i= 1,1 do
    local monthname = string.lower(os.date
                      ("%B",os.time{year=year,month=i,day=1}))

    context.setupheadertexts(
      {
        function()
          context("\\bf")
          context.labeltext(monthname)
          return true
        end
      },
      {
        function()
          context(year)
          return true
        end
      },
      { 
        function()
          context("\\bf")
          context.labeltext(monthname)
          return true
        end
      },
      {
        function()
          context(year)
          return true
        end
      })

    thirddata.diary.monthblock(i,year,lat,lon,timeoffset,dst_start,dst_stop)
  end
end

function thirddata.diary.monthblock(
  month,year,lat,lon,timeoffset,dst_start,dst_stop)

  report("Working in function diary.monthblock")

  local c = thirddata.calendar.month(month,year) --returns number of weeks in a given month
  local wkf = thirddata.calendar.weeknumber(1,month,year)

  --report("Weeks in the selected month: %s", c)
  --report("Week number : %s", wkf)

  local nofdays = 1

  if month == 2 and thirddata.calendar.isleapyear(year) ~= 365 then
    nofdays = thirddata.calendar.nofdays_month(month,year) + 1
  else
    nofdays = thirddata.calendar.nofdays_month(month,year)
  end

  report("Number of days in month: %s", nofdays)

  local wkl = thirddata.calendar.weeknumber(nofdays,month,year)

  local monthname = thirddata.calendar.select_nameofmonth(month,year)

  context.bTABLE({setups="table:monthblock"})

    for i = 1,nofdays do

      local ordinalday  = thirddata.calendar.ordinalday(i,month,year)
      local weeknumber = thirddata.calendar.weeknumber(i,month,year)
      local holiday    = thirddata.calendar.checkchristianfeast(i,month,year) 
      local moondata   = thirddata.moonphase.lunardays(year,month,i)
      local sunrise,sunset,lighthours =
              thirddata.srss.sundata(
                i,month,year,lat,lon,timeoffset,dst_start,dst_stop)

      context.bTR()
         context.bTD()

          local dayname = string.lower(os.date
                            ("%a",os.time{day=i,month=month,year=year}))

          --report("Dayname: %s",dayname)
          context.starttabulate{"|lw(0.1\\textwidth)|lw(0.06\\textwidth)|l|"}
            context.NC()
              if  dayname == "sun" or holiday ~= "" and holiday ~= "asw" then
                local dnu = i
                local dna = dayname
                context.color({"red"},
                function() context(dnu) end)                --day number
                context("~")
                context.color({"red"},
                function() context.labeltext(dna) end)--dayname
              else  
                context(i)                 --day
                context("~")
                context.labeltext(dayname) --dayname
              end
            context.NC()
            context.switchtobodyfont{"6pt"}
              context.labeltext("week")
              context(": ")
              context(weeknumber)
            context.NC()
              context.switchtobodyfont{"6pt"}
              context.labeltext("day")
              context(": ")
              context(ordinalday)
            context.NC()
            context.NR()
          context.stoptabulate()
        context.eTD()
        context.bTD()
          context.starttabulate{"|lw(0.2\\textwidth)|l|l|l|l|"}
          context.NC()
            if holiday == "" then
              context.strut()
              context.NC()
              context.NC()
              context.NC()
              context.NC()              
            else
              context.labeltext(holiday)
              context.NC()
              context.NC()
              context.NC()
              context.NC()            
            end
            context.NR()
              context.NC()
                if tonumber(moondata) then
                  context.labeltext("moondays")
                else
                  context.labeltext("moon")
                end          
                  context(":~")
                  context(moondata)
               context.NC()
                 --context.labeltext("sunrise")
                 context("\\SunA[background=Sunrise]{}")
                 context("\\quad :~")
                 context(sunrise)
               context.NC()
                 context("\\SunA[background=Sunset]{}") 
                 context("\\quad :~")
                 context(sunset)
               context.NC()
                 context("\\SunB[background=Light]{}")
                 context("~:~")
                 context(lighthours)
               context.NC()
             context.NR()
           context.stoptabulate()
        context.eTD()
      context.eTR()
    end
  context.eTABLE()
  context.page()
end

\stopluacode   

\startsetups[table:monthblock]
  \setupTABLE[split=yes]
  \setupTABLE[each][each][frame=on]
  \setupTABLE[r][each][offset=0pt,loffset=3pt,roffset=3pt,align=lohi] 
  \setupTABLE[c][1][width=0.35\textwidth,align=lohi] 
  \setupTABLE[c][2][style={\switchtobodyfont[6pt]},width=0.65\textwidth] \stopsetups

\define[5]\Yearofmonthtables{\ctxlua{thirddata.diary.year_of_monthtables(#1,#2,#3,#4,#5)}}

\startbuffer[Yearofmonthtables]
  \Yearofmonthtables %Year,lat,lon,timeoffset,dst_start,dst_stop
     {\getvariable{PocketDiary}{Year}}
     {\getvariable{PocketDiaryGeoPosition}{lat}}
     {\getvariable{PocketDiaryGeoPosition}{lon}}
     {\getvariable{PocketDiaryGeoPosition}{timeoffset}}
     {"\getvariable{PocketDiaryGeoPosition}{continent}"}
\stopbuffer

% Implement international interface:
\setuplabeltext[en][title=Title]
\setuplabeltext[nl][title=Titel]
\setuplabeltext[de][title=Titel]
\setuplabeltext[fr][title=Titre]
\setuplabeltext[it][title=Titolo]
\setuplabeltext[es][title=Título]

\setuplabeltext[en][author=Author]
\setuplabeltext[nl][author=Auteur]
\setuplabeltext[de][author=Autor]
\setuplabeltext[fr][author=Auteur]
\setuplabeltext[it][author=autore]
\setuplabeltext[es][author=Autor]

\setuplabeltext[en][typography=Typography]
\setuplabeltext[nl][typography=Typografie]
\setuplabeltext[de][typography=Typographie]
\setuplabeltext[fr][typography=Typographie]
\setuplabeltext[it][typography=Tipografia]
\setuplabeltext[es][typography=Tipografía]

\setuplabeltext[en][compilation=Compilation date]
\setuplabeltext[nl][compilation=Compilatie datum]
\setuplabeltext[de][compilation=Kompilationsdatum]
\setuplabeltext[fr][compilation=Date de compilation]
\setuplabeltext[it][compilation=Dato di compilazione]
\setuplabeltext[es][compilation=Fecha de compilación]

\starttext

 \startstandardmakeup[page=yes,doublesided=no]
   \strut
   \startalignment [middle]
      \godown[.3\textheight]
      \startmode[English]
        {\bfc \labeltext{sunstar}- and \labeltext{moon}-\labeltext{calendar}}
      \stopmode
      \startmode[Dutch]
        {\bfc \labeltext{sunstar}- en \labeltext{moon}-\labeltext{calendar}}
      \stopmode
      \startmode[German]
        {\bfc \labeltext{sunstar}n- und \labeltext{moon}-\labeltext{calendar} }
      \stopmode
      \startmode[French]
        {\bfc \labeltext{calendar} du \labeltext{sunstar}
          et de la \labeltext{moon}}
      \stopmode
      \startmode[Italian]
        {\bfc \labeltext{calendar} di \labeltext{sunstar}
          e della \labeltext{moon}}
      \stopmode
      \startmode[Spanish]
        {\labeltext{calendar} del \labeltext{sunstar} 
          y la \labeltext{moon}}
      \stopmode
      \blank
      {\bfb \getvariable{PocketDiary}{Place}}
      \vfill
      {\tfa \getvariable{PocketDiary}{Year}}
    \stopalignment
    \vfil
  \stopstandardmakeup

  \startstandardmakeup[page=yes,doublesided=no]
    \starttabulate[|l|p|]
      \NC \labeltext{title} 
      \EQ       
        \startmode[English]
          {\labeltext{sunstar}- and \labeltext{moon}-\labeltext{calendar}}
        \stopmode
        \startmode[Dutch]
          {\labeltext{sunstar}- en \labeltext{moon}-\labeltext{calendar}}
        \stopmode
        \startmode[German]
          {\labeltext{sunstar}n- und \labeltext{moon}-\labeltext{calendar}}
        \stopmode
        \startmode[French]
          {\labeltext{calendar} du \labeltext{sunstar}
             et de la \labeltext{moon}}
        \stopmode
        \startmode[Italian]
          {\labeltext{calendar} di \labeltext{sunstar}
            e della \labeltext{moon}}
        \stopmode
        \startmode[Spanish]
          {\labeltext{calendar} del \labeltext{sunstar}
            y la \labeltext{moon}}
        \stopmode
      \NC\NR
      \NC \labeltext{author}
      \EQ \getvariable{PocketDiaryAddress}{Forename}~
          \getvariable{PocketDiaryAddress}{Familyname} \NC\NR
      \NC \labeltext{typography} \EQ \CONTEXT\ with \LUAMETATEX \NC\NR
      \NC \labeltext[compilation] \EQ \currentdate \NC\NR
    \stoptabulate
    \vfil
    \startmode[English]
      This calendar is generated for \getvariable{PocketDiary}{Place},       
        \getvariable{PocketDiary}{Country}
    \stopmode
    \startmode[German]
      Dieser Kalender ist berechnet für \getvariable{PocketDiary}{Place}, 
        \getvariable{PocketDiary}{Country}
    \stopmode
    \startmode[Dutch]
      Deze kalender is opgemaakt voor \getvariable{PocketDiary}{Place}, 
        \getvariable{PocketDiary}{Country}
    \stopmode
    \startmode[French]
      Ce calendrier est fait pour \getvariable{PocketDiary}{Place}, 
        \getvariable{PocketDiary}{Country}
    \stopmode
    \startmode[Italian]
     Questo calendario è prodotto per \getvariable{PocketDiary}{Place}, 
       \getvariable{PocketDiary}{Country}
    \stopmode
    \startmode[Spanish]
      Este calendario está calculado para \getvariable{PocketDiary}{Place}, 
        \getvariable{PocketDiary}{Country}
    \stopmode
    \starttabulate[|l|r|]
      \NC Longitude \EQ \getvariable{PocketDiaryGeoPosition}{lon} \NC\NR
      \NC Latitude  \EQ  \getvariable{PocketDiaryGeoPosition}{lat} \NC\NR
    \stoptabulate
  \stopstandardmakeup
  
  \getbuffer[Yearofmonthtables]

\stoptext