-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmadpinklib.livecodescript
More file actions
2086 lines (1836 loc) · 59.4 KB
/
madpinklib.livecodescript
File metadata and controls
2086 lines (1836 loc) · 59.4 KB
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--name: libMadPink
--vers: 2.5.0
--date: 2022-01-29
--full: MadPink Master Lib
on __Documentation_Template__
/*
First version is simple
*/
--handler commandOrFunctionName
--desc Insert description here
--param pVal - the current counter value
--returns - (number/boolean/string)
--trigger - field/widget/button names
--effects - field/widget/button names
/*
Second version is more detailed
*/
--fnord
/* help: commandOrFunctionName
PARAMETERS:
pParam (required) parameter description; fixed options
--"open" first of parameter options
--"close" second of parameter options
----default: "open"
pParam2 (optional) parameter description; boolean/numeric/text
----default: true
DESCRIPTION: insert_description_here
returns - (number/boolean/string)
trigger - field/widget/button names
*/
--don't panic
end __Documentation_Template__
function getPink pName
put char 1 to 3 of pName into pName
switch pName
case "dee" -- DeepPink
return hexToRGB("FF1493")
break
case "spi" -- SpicyPink
return hexToRGB("FF1CAE")
break
case "sho" -- ShockingPink
return hexToRGB("FF0FC0")
break
case "bri" -- BrightPink
return hexToRGB("FF007F")
break
case "hol" -- HollywoodPink
return hexToRGB("F400A1")
break
default
case "cer" -- Cerise
return hexToRGB("DA3287")
break
end switch
end getPink
on ___DATAFILES___
end ___DATAFILES___
command mpDataFile pData pPropSet pFileName pSupportFol pSFP pStackName
/*
REQUIRED:
pData - data to save, or command(load, close);
--"load" the data from the file is put into "the result"
--"close" the data file will be closed
OPTIONAL:
--pPropSet - name of the property set to save/load, default: mpData
--pFileName - file name for the save file, default: MadPinkApp.mpd
--pSupportFol - folder and subfolder(s) to store file, default: pink.mad.data/STACKNAME
--pSFP - special folder path in which to put the above folders, default is based on operating system
--pStackName - name for the save stack, default is the filename without extension plus "_Data"
*/
local tPath, tFolder, tKey
-----
set itemdel to "."
if pPropSet is empty then
put "mpData" into pPropSet
end if
put mpGenerateFilePath(pFileName, pSupportFol, pSFP) into tPath
if pFileName is empty then
put "MadPinkApp.mpd" into pFileName
end if
if pStackName is empty then
put item 1 to -2 of pFileName & "_Data" into pStackName
end if
if pData is "close" then
close stack pStackName
return "Completed"
end if
set the defaultFolder to tPath
put "/" & pFileName after tPath
if pData is "filepath" then
return tPath
end if
if pStackName is not among the lines of the openStacks then
if there is no file tPath then
create invisible stack pStackName
set the destroyStack of stack pStackName to true
save stack pStackName as tPath
else
open invisible stack tPath
end if
end if
if pData is "load" then
return the customProperties[pPropSet] of stack pStackName
else
set the customProperties[pPropSet] of stack pStackName to pData
save stack pStackName as tPath
break
end if
end mpDataFile
function mpDataFileLoad pPropSet pFileName pSupportFol pSFP pStackName
mpDataFile, "load", pPropSet, pFileName, pSupportFol, pSFP, pStackName
return the result
end mpDataFileLoad
function mpDataFilePath pPropSet pFileName pSupportFol pSFP pStackName
mpDataFile, "filepath", pPropSet, pFileName, pSupportFol, pSFP, pStackName
return the result
end mpDataFilePath
function mpGenerateFilePath pFileName pSupportFol pSFP
local tPath, tFolder
-----
if pFileName is empty then
put "MadPinkApp.mpd" into pFileName
end if
if pSupportFol is empty then
put "pink.mad.data/" & item 1 to -2 of pFileName into pSupportFol
replace space with "_" in pSupportFol
end if
if pStackName is empty then
put item 1 to -2 of pFileName & "_Data" into pStackName
end if
if pData is "close" then
close stack pStackName
return "Completed"
end if
if pSFP is not empty then
put specialFolderPath(pSFP) into tPath
else if pSFP is "usepath" then
put empty into tPath
else if the platform is "MacOS" or the platform is "Win32" then
put specialFolderPath("support") into tPath
else if the platform is "iphone" or the platform is "android" then
put specialFolderPath("documents") into tPath
else
put specialFolderPath("home") into tPath
end if
set itemdel to "/"
repeat for each item tFolder in pSupportFol
put "/" & tFolder after tPath
if there is not a directory tPath then
create folder tPath
end if
end repeat
set the defaultFolder to tPath
put "/" & pFileName after tPath
return tPath
end mpGenerateFilePath
on ___TEXTFILES___
end ___TEXTFILES___
command mpTextFileWrite pText pFileName pSupportFol pSFP
/*
REQUIRED:
pText - data to load
OPTIONAL:
--pFileName - file name for the save file, default: MadPinkApp.mpd
--pSupportFol - folder and subfolder(s) to store file, default: pink.mad.data/STACKNAME
--pSFP - special folder path in which to put the above folders, default is based on operating system
*/
local tPath
-----
if pFileName is empty then
put "MadPinkApp.txt" into pFileName
end if
put mpGenerateFilePath(pFileName, pSupportFol, pSFP) into tPath
set the defaultFolder to tPath
put "/" & pFileName after tPath
open file tPath for write
write pText to file tPath
close file tPath
end mpTextFileWrite
command mpTextFileRead pFileName pSupportFol pSFP
/*
REQUIRED:
OPTIONAL:
--pFileName - file name for the save file, default: MadPinkApp.txt
--pSupportFol - folder and subfolder(s) to store file, default: pink.mad.data/STACKNAME
--pSFP - special folder path in which to put the above folders, default is based on operating system
*/
local tPath, tText
-----
if pFileName is empty then
put "MadPinkApp.txt" into pFileName
end if
put _mpGenerateFilePath(pFileName, pSupportFol, pSFP) into tPath
set the defaultFolder to tPath
put "/" & pFileName after tPath
open file tPath for read
read from file tPath until EOF
put it into tText
close file tPath
return tText
end mpTextFileRead
on ___STATS___
end ___STATS___
function freqFromArray pArray pMap pReturn
local tFreqs, tMapDepth, tValueToCount, tList, tRecord
set itemdel to semicolon
put (the number of items in pMap)into tMapDepth
put the keys of pArray into tList
repeat for each line x in tList
put pArray[x] into tRecord
repeat with y=1 to tMapDepth
put tRecord[item y of pMap] into tRecord
end repeat
if tRecord is empty then
next repeat
else
repeat for each item z in tRecord
add 1 to tFreqs[z]
end repeat
end if
end repeat
if pReturn is "array" then
return tFreqs
else
return freqArrayFlatten(tFreqs)
end if
end freqFromArray
private function freqArrayFlatten pArray
local tList, tFreqTable
put the keys of pArray into tList
sort tList
repeat for each line x in tList
put x & tab & pArray[x] & cr after tFreqTable
end repeat
return tFreqTable
end freqArrayFlatten
on ___BASICS___
end ___BASICS___
function doEveryX pVal pX
--desc Use when you want something to happen at certain intervals, for example provide update everytime the counter pass a multiple of 100
--param pVal - the current counter value
--param pX - the base to work on for example '100'
--returns - boolean
if (pVal/pX) = trunc(pVal/pX) then
return true
else
return false
end if
end doEveryX
command showGroup pGroup
--param pGroup - group to display
set the vis of group pGroup to true
set the layer of group pGroup to top
end showGroup
command hideGroup pGroup
--param pGroup - group to hide
set the vis of group pGroup to false
end hideGroup
command setTreeData pData pTree
if pTree is empty then
put "treeData" into pTree
end if
set the arrayData of widget pTree to pData
end setTreeData
function getTreeData pTree
if pTree is empty then
put "treeData" into pTree
end if
return the arrayData of widget pTree
end getTreeData
function fixVal pValue pDefault pOtherRule
if pValue is empty then
return pDefault
end if
switch pOtherRule
case "number"
if pValue is not a number then
return pDefault
end if
break
case "string"
if pValue is not text then
return pDefault
end if
break
case "array"
if pValue is not an array then
return pDefault
end if
break
end switch
return pValue
end fixVal
on ___TEXT_AND_NUMBERS___
end ___TEXT_AND_NUMBERS___
command txtFormat pStyle
--param pStyle - plain, bold, box, italic, underline, strikeout
if pStyle is "plain" or pStyle is empty then
set the textStyle of selectedText to plain
else if the selectedText is not empty then
set the textStyle[pStyle] of selectedText to not(the textStyle[pStyle] of selectedText)
end if
end txtFormat
command txtAlign pAlign
--param pStyle - center, left, right
set the textAlign of selectedText to pAlign
end txtAlign
command txtSize pSize pStep
local tSetSize
if pStep is empty then
put 2 into pStep
end if
put the textSize of selectedText into tSetSize
if pSize is "up" then
add pStep to tSetSize
else if pSize is "down" then
subtract pSize from tSetSize
end if
set the textSize of selectedText to tSetSize
end txtSize
command txtFont pFont
if pFont is "Fixed" then
put "Courier" into pFont
else if pFont is empty then
put "Arial" into pFont
end if
set the textFont of selectedText to pFont
end txtFont
function padZero pNum pDigits
local tFixer, tUpper
--param pNum - number to pad
--param pDigits - number of digits to pad
put 10 ^ pDigits into tFixer
subtract 1 from pDigits
put 10 ^ pDigits into tUpper
if pNum < tUpper then
add tFixer to pNum
put char 2 to -1 of pNum into pNum
end if
return pNum
end padZero
function padText pText pLength pPadWith pPlace
--DX param pText - Text to pad
--DX param pLength - number of places to have in total
--DX param pPad - [space] - item to use for padding
--DX param pPlace - [end],start - where to pad
if pPadWith is empty then put space into pPadWith
subtract length(pText) from pLength
if pLength < 1 then return pText
repeat pLength times
switch pPlace
case "start"
put pPadWith before pText
break
default
case "end"
put pPadWith after pText
break
end switch
end repeat
return pText
end padText
function enQ pText
--desc Enquote the text
--param pText - text to enquote
--returns the text in quotes
put quote before pText
put quote after pText
return pText
end enQ
function qzQ pText
return quazQua(pText,"decode")
end qzQ
function qzZ pText
return quazQua(pText,"encode")
end qzZ
function quazQua pText pDirection pMaintainPlaceholder
if pMaintainPlaceholder is true then
replace "qzqzz" with "q1z1q1z1" in pText
replace "qzqxx" with "q1z1q1x1" in pText
end if
switch pDirection
case "fullencode"
case "fenc"
replace quote with "qzqq" in pText
replace quote & comma & quota with "qzqv" in pText
replace "'" with "qzqa" in pText
replace cr with "qzqz"in pText
replace tab with "qzqt" in pText
replace colon with "qzqc" in pText
replace semicolon with "qzqs" in pText
break
case "fulldecode"
case "fdec"
replace "qzqq" with quote in pText
replace "qzqz" with cr in pText
replace "qzqt" with tab in pText
replace "qzqv" with quote & comma & quota in pText
replace "qzqa" with "'" in pText
replace "qzqc" with colon in pText
replace "qzqs" with semicolon in pText
break
case "encode"
case "qit"
replace quote with "qzqq" in pText
replace cr with "qzqz"in pText
replace tab with "qzqt" in pText
break
case "decode"
case "unq"
default
replace "qzqt" with tab in pText
replace "qzqz" with cr in pText
replace "qzqq" with quote in pText
break
end switch
if pMaintainPlaceholder is true then
replace "q1z1q1z1" with "qzqzz" in pText
replace "q1z1q1x1" with "qzqxx" in pText
end if
return pText
end quazQua
function thymeStamp pType pPrefix pTime pOffset
local tThyme
--param pPrefix - optional, prefix to use
--param pType - optional, z=seconds; s=seconds; m=minutes; d=day
--param pTime - optional, time to use instead of now
--param pOffset - optional, seconds to offset
if pTime is empty then
put the seconds into pTime
end if
if pPrefix is not empty then
put pPrefix into tThyme
end if
if pType is not empty then
put char 1 of pType into pType
else
put "s" into pType
end if
if pOffset is true or pOffset is "v" then
put 1508342097 into pOffset
end if
if pType is "z" then
convert pTime to seconds
subtract pOffset from pTime
put pTime after tThyme
return tThyme
end if
convert pTime to dateItems
set itemdel to comma
put item 1 of pTime after tThyme
put padZero(item 2 of pTime,2) after tThyme
put padZero(item 3 of pTime,2) after tThyme
if pType is "d" then
return tThyme
end if
put padZero(item 4 of pTime,2) after tThyme
put padZero(item 5 of pTime,2) after tThyme
if pType is "m" then
return tThyme
end if
put padZero(item 6 of pTime,2) after tThyme
return tThyme
end thymeStamp
on ___SCRIPTS_AND_STACKS___
end ___SCRIPTS_AND_STACKS___
command updateVersionNumber pType pName
local tProps, tVers
put the customProperties["cRevStandaloneSettings"] of this stack into tProps
switch pType
case "major"
add 1 to tProps["Windows,fileversion1"]
break
case "minor"
add 1 to tProps["Windows,fileversion2"]
break
case "sub"
add 1 to tProps["Windows,fileversion4"]
break
case "build"
default
add 1 to tProps["Windows,fileversion3"]
break
end switch
if pName is empty then
put tProps["Windows,ProductName"] into pName
else
put pName into tProps["Windows,ProductName"]
end if
put tProps["Windows,fileversion1"] & "." & tProps["Windows,fileversion2"] & "." & tProps["Windows,fileversion3"] into tVers
if pType is "sub" then
put "." & tProps["Windows,fileversion4"] into tVers
end if
put pName & tVers into tProps["name"]
put pName && tVers && "For Windows" into tProps["Windows,FileDescription"]
put pName & tVers into tProps["OSX,name"]
put pName && tVers into tProps["OSX,longVersion"]
put tVers into tProps["OSX,shortVersion"]
set the customProperties["cRevStandaloneSettings"] of this stack to tProps
end updateVersionNumber
command incrementVersion pType pName pField pCurrent
local tVersion, tBuild, tProps
--param pType - [build], patch, minor, major - item to increment
--param pName - optional, application name if you want to append version and include it (use "current" to play with whatever is already there)
--param pField - optional, if you want to fill a field with the number
--param pCurrent - optional, use if you want to manually start at a certain point (or if cVersion is empty)
set the itemdel to "."
put the customProperties["cRevStandaloneSettings"] of this stack into tProps
if pCurrent is empty then
put the cVersion of this stack into tVersion
else
put pCurrent into tVersion
end if
if tVersion is empty then put "0.0.0" into tVersion
put the cBuild of this stack into tBuild
if tBuild is empty then put 1 into tBuild
add 1 to tBuild
switch pType
case "patch"
add 1 to item 3 of tVersion
break
case "minor"
add 1 to item 2 of tVersion
break
case "major"
add 1 to item 1 of tVersion
break
case "build"
default
add 1 to tBuild
break
end switch
put tVersion into tProps["ios,bundleversion"]
put item 1 of tVersion into tProps["Windows,fileversion1"]
put item 2 of tVersion into tProps["Windows,fileversion2"]
put item 3 of tVersion into tProps["Windows,fileversion3"]
put tBuild into tProps["Windows,fileversion4"]
put tVersion into tProps["ios,bundle version"]
if pName is "current" then
put tProps["Windows,ProductName"] into pName
end if
if pName is not empty then
put pName into tProps["Windows,ProductName"]
put pName & tVers into tProps["name"]
put pName && tVers && "For Windows" into tProps["Windows,FileDescription"]
put pName & tVers into tProps["OSX,name"]
put pName && tVers into tProps["OSX,longVersion"]
put tVers into tProps["OSX,shortVersion"]
end if
set the customProperties["cRevStandaloneSettings"] of this stack to tProps
set the cVersion of this stack to tVersion
set the cBuild of this stack to tBuild
if pField is not empty then put tVersion into field pField
end incrementVersion
function scanScriptForDox pScript
local tLine, tItem, tDocList
set itemdel to space
repeat for each line tLine in pScript
repeat
if char 1 of tLine is space then put char 2 to -1 of tLine into tLine else exit repeat
end repeat
if item 1 of tLine is "command" or item 1 of tLine is "function" then
else if char 1 to 4 of tLine is not "--DX" then
next repeat
else
put item 2 to -1 of tLine into tLine
end if
put item 1 of tLine into tItem
put char 1 to 4 of tItem into tItem
switch tItem
case "comm"
case "func"
put cr before tLine
break
case "desc"
put item 2 to -1 of tLine into tLine
put space & space before tLine
-- put "--" before tLine
break
case "para"
case "exam"
case "retu"
put space & space & space & space before tLine
break
case "z"
put space & space & space & space & space before tLine
break
end switch
put tLine & cr after tDocList
end repeat
return char 2 to -1 of tDocList
end scanScriptForDox
on ___AGE_AND_DATES__
end ___AGE_AND_DATES__
--631152000 20
--1262304000 40
--1893456000 60
--2524608000 80
function unixAge pSec
return calculateAge("seconds",pSec)
end unixAge
function dateItemsToSeconds pDate
set itemdel to comma
put item 1 of pDate into tYear
if tYear >=1970 then
convert pDate to seconds
else if tYear >= 1950 then
add 20 to item 1 of pDate
convert pDate to seconds
subtract 631152000 from pDate
else if tYear >= 1930 then
add 40 to item 1 of pDate
convert pDate to seconds
subtract 1262304000 from pDate
else if tYear >= 1910 then
add 60 to item 1 of pDate
convert pDate to seconds
subtract 1893456000 from pDate
else if tYear >= 1890 then
add 80 to item 1 of pDate
convert pDate to seconds
subtract 2524608000 from pDate
end if
if pDate is not a number then return empty
return pDate
end dateItemsToSeconds
function dateToSeconds pDate
if pDate ends with "00:00:00" then
put char 1 to -10 of pDate into pDate
set itemdel to tab
replace "-" with tab in pDate
put item 2 of pDate & slash & item 3 of pDate & slash & item 1 of pDate into pDate
end if
set itemdel to "/"
put item 3 of pDate into tY
if tY < 20 then
add 2000 to tY
else if tY < 1900 then
add 1900 to tY
end if
put tY & comma & item 1 of pDate & comma & item 2 of pDate & ",0,0,0,0" into fDate
put dateItemsToSeconds(fDate) into fDate
if fDate is not a number then return fDate
return fDate
end dateToSeconds
function secondsToDateItems pSec
if pSec is not a number then return empty
set itemdel to comma
if pSec >= 0 then
convert pSec to dateItems
else if pSec > -631152000 then
add 631152000 to pSec
convert pSec to dateItems
subtract 20 from item 1 of pSec
else if pSec > -1262304000 then
add 1262304000 to pSec
convert pSec to dateItems
subtract 40 from item 1 of pSec
else if pSec > -1893456000 then
add 1893456000 to pSec
convert pSec to dateItems
subtract 60 from item 1 of pSec
else
add 2524608000 to pSec
convert pSec to dateItems
subtract 80 from item 1 of pSec
end if
return pSec
end secondsToDateItems
function xYearsAgoInSeconds pYears
put the short date into tCurrent
convert tCurrent to dateitems
set itemdel to comma
subtract pYears from item 1 of tCurrent
return dateItemsToSeconds(tCurrent)
end xYearsAgoInSeconds
function xMonthsAgoInSeconds pMonths
put the short date into tCurrent
convert tCurrent to dateitems
set itemdel to comma
put trunc(pMonths/12) into tYears
put pMonths-(tYears*12) into tMonths
if pMonths >= item 2 of tCurrent then
add 1 to tYears
subtract 12 from pMonths
end if
subtract tYears from item 1 of tCurrent
subtract pMonths from item 2 of tCurrent
return dateItemsToSeconds(tCurrent)
end xMonthsAgoInSeconds
function dateFromSeconds pSec
return formatDateItemsToDate(pSec,true)
end dateFromSeconds
function formatDateItemsToDate pDate pConvertFirst
if pConvertFirst is true then put secondsToDateItems(pDate) into pDate
set itemdel to comma
put item 2 of pDate & slash into tRez
put item 3 of pDate & slash after tRez
put item 1 of pDate after tRez
return tRez
end formatDateItemsToDate
function ageFromSeconds pSec
return calculateAge("seconds",pSec)
end ageFromSeconds
function calculateAge pYear pMonth pDay
replace space with empty in pYear
replace space with empty in pMonth
if pYear is empty then return empty
if pMonth is empty then return empty
if pYear is "seconds" then
put secondsToDateItems(pMonth) into tTime
put item 1 of tTime into pYear
put item 2 of tTime into pMonth
put item 3 of tTime into PDay
end if
put the long date into tToday
convert tToday to dateItems --OK
set itemdel to comma
put item 1 of tToday into tYear
put tYear-pYear into age
if item 2 of tToday < pMonth then subtract 1 from age
if item 2 of tToday = pMonth then
if item 3 of tToday < pDay then subtract 1 from age
end if
if age < 0 then add 100 to age
return age
end calculateAge
function timeSince pStartTime pEndTime pForm
if pEndTime is empty then put the seconds into pEndTime
put pEndTime-pStartTime into timeBetween
put timeBetween/86400 into tDays
put tDays/30 into tMonths
put tDays/365.25 into tYears
switch pForm
case "years"
return tYears
break
case "months"
return tMonths
break
case "days"
return tDays
break
default
--if pForm is blank, we do months or years with label
if tDays < 365 then
return round(tMonths,1) && "Months"
else
return round(tYears,1) && "Years"
end if
break
end switch
end timeSince
function cleanPhone pPhone
put 0 into tCount
repeat for each char x in pPhone
if x is a number then
put x after newPhone
add 1 to tCount
end if
if tCount = 10 then exit repeat
end repeat
return newPhone
end cleanPhone
function reformatPhone pPhone
put 0 into tCount
repeat for each char x in pPhone
if x is not a number then next repeat
add 1 to tCount
switch
case tCount=1
put "(" & x into tPhoneNumber
break
case tCount=4
put ") " & x after tPhoneNumber
break
case tCount=7
put "-" & x after tPhoneNumber
break
default
put x after tPhoneNumber
break
end switch
if tCount = 10 then exit repeat
end repeat
return tPhoneNumber
end reformatPhone
function parseThymeStamp pStamp
if pStamp is not a number then return empty
convert pStamp to dateitems --OK
set itemdel to comma
put item 1 of pStamp & tab into tReturn
put "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec" into theMonths
put item 2 of pStamp into tMo
if tMo is not a number then return empty
put item tMo of theMonths & tab after tReturn
put item 3 of pStamp after tReturn
return tReturn
end parseThymeStamp
function monthNumToName pMon
put "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec" into tMonths
set itemdel to comma
if pMon is not a number then return empty
return item pMon of tMonths
end monthNumToName
function monthNameToNum pMon
put char 1 to 3 of pMon into pMon
switch pMon
case "Jan"
return 1
break
case "Feb"
return 2
break
case "Mar"
return 3
break
case "Apr"
return 4
break
case "May"
return 5
break
case "Jun"
return 6
break
case "Jul"
return 7
break
case "Aug"
return 8
break
case "Sep"
return 9
break
case "Oct"
return 10
break
case "Nov"
return 11
break
case "Dec"
return 12
break
end switch
end monthNameToNum
function newID pType
wait 1 second
put the seconds into temp
subtract 1508342097 from temp
if pType is empty then put "id_" before temp else put pType before temp
return temp
end newID
on __AYANS__
end __AYANS__
/*
-- libAYANS 0.3.14
And Yet Another Notation System
indentation doesn't matter, just for readability
any leading spaces are deleted, to put actual leading spaces in use "~"
the tilde will be the first space
if your first character is a tilde, you are SOL
single key value combos
= single value on this line inline
_ single value is the next line (underscore)
| single value spans mutliple lines including line breaks
> single value spans multiple lines substituting space for line breaks
- simple array of items
! complex/nested array
end multiline/array with semicolon & key name