|
@@ -8,24 +8,28 @@ if $ARGS[0] = '':
|
|
! sync totminut with daystart, hour, and minut
|
|
! sync totminut with daystart, hour, and minut
|
|
totminut = minut + hour * 60 + (daystart - 1) * 1440
|
|
totminut = minut + hour * 60 + (daystart - 1) * 1440
|
|
|
|
|
|
- :time_time_loop
|
|
|
|
- time_temp_jump_flag = 0
|
|
|
|
- if minut >= 60:
|
|
|
|
- !! Hourly Changes
|
|
|
|
- hour += 1
|
|
|
|
- minut -= 60
|
|
|
|
- gs 'hourly_events'
|
|
|
|
- time_temp_jump_flag = 1
|
|
|
|
- end
|
|
|
|
- if hour >= 24:
|
|
|
|
- hour -= 24
|
|
|
|
- daystart += 1
|
|
|
|
- gs 'time', 'update_date'
|
|
|
|
- gs 'cikl'
|
|
|
|
- time_temp_jump_flag = 1
|
|
|
|
- end
|
|
|
|
- if time_temp_jump_flag = 1: jump 'time_time_loop'
|
|
|
|
- killvar 'time_temp_jump_flag'
|
|
|
|
|
|
+ if totminut ! prevtotmin:
|
|
|
|
+ :time_time_loop
|
|
|
|
+ time_temp_jump_flag = 0
|
|
|
|
+ if minut >= 60:
|
|
|
|
+ !! Hourly Changes
|
|
|
|
+ hour += 1
|
|
|
|
+ minut -= 60
|
|
|
|
+ gs 'hourly_events'
|
|
|
|
+ time_temp_jump_flag = 1
|
|
|
|
+ end
|
|
|
|
+ if hour >= 24:
|
|
|
|
+ hour -= 24
|
|
|
|
+ daystart += 1
|
|
|
|
+ gs 'time', 'update_date'
|
|
|
|
+ gs 'cikl'
|
|
|
|
+ time_temp_jump_flag = 1
|
|
|
|
+ end
|
|
|
|
+ if time_temp_jump_flag = 1: jump 'time_time_loop'
|
|
|
|
+ killvar 'time_temp_jump_flag'
|
|
|
|
+
|
|
|
|
+ gs 'time', 'update_daystage', year, month, day, hour, minut
|
|
|
|
+ end
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
@@ -44,82 +48,84 @@ end
|
|
|
|
|
|
! ARGS[1] = daystart
|
|
! ARGS[1] = daystart
|
|
if $ARGS[0] = 'to_date':
|
|
if $ARGS[0] = 'to_date':
|
|
|
|
+ if arrsize('ARGS') = 1: ARGS[1] = daystart
|
|
|
|
+
|
|
!daystart = 1 -> 1 Jan 2016
|
|
!daystart = 1 -> 1 Jan 2016
|
|
!mod_daystart = 0 -> 1 Jan 2013
|
|
!mod_daystart = 0 -> 1 Jan 2013
|
|
|
|
|
|
- mod_daystart = ARGS[1] + 1094
|
|
|
|
|
|
+ temp_timeVars['mod_daystart'] = ARGS[1] + 1094
|
|
|
|
|
|
- dateVars['week'] = (mod_daystart + 2) mod 7
|
|
|
|
|
|
+ dateVars['week'] = (temp_timeVars['mod_daystart'] + 2) mod 7
|
|
if dateVars['week'] = 0: dateVars['week'] = 7
|
|
if dateVars['week'] = 0: dateVars['week'] = 7
|
|
|
|
|
|
dateVars['year'] = 2013
|
|
dateVars['year'] = 2013
|
|
- temp_4cycles = mod_daystart / 1461 & ! (cycle of 4 years)
|
|
|
|
- dateVars['year'] += 4 * temp_4cycles
|
|
|
|
|
|
+ temp_timeVars['4cycles'] = temp_timeVars['mod_daystart'] / 1461 & ! (cycle of 4 years)
|
|
|
|
+ dateVars['year'] += 4 * temp_timeVars['4cycles']
|
|
|
|
|
|
! The remaining years in this cycle of 4 years
|
|
! The remaining years in this cycle of 4 years
|
|
- if mod_daystart mod 1461 >= 1095:
|
|
|
|
- temp_inner_years = 3
|
|
|
|
- elseif mod_daystart mod 1461 >= 730:
|
|
|
|
- temp_inner_years = 2
|
|
|
|
- elseif mod_daystart mod 1461 >= 365:
|
|
|
|
- temp_inner_years = 1
|
|
|
|
|
|
+ if temp_timeVars['mod_daystart'] mod 1461 >= 1095:
|
|
|
|
+ temp_timeVars['inner_years'] = 3
|
|
|
|
+ elseif temp_timeVars['mod_daystart'] mod 1461 >= 730:
|
|
|
|
+ temp_timeVars['inner_years'] = 2
|
|
|
|
+ elseif temp_timeVars['mod_daystart'] mod 1461 >= 365:
|
|
|
|
+ temp_timeVars['inner_years'] = 1
|
|
else
|
|
else
|
|
- temp_inner_years = 0
|
|
|
|
|
|
+ temp_timeVars['inner_years'] = 0
|
|
end
|
|
end
|
|
- dateVars['year'] += temp_inner_years & ! The remaining years in this cycle of 4 years
|
|
|
|
|
|
+ dateVars['year'] += temp_timeVars['inner_years'] & ! The remaining years in this cycle of 4 years
|
|
|
|
|
|
|
|
|
|
- temp_inner_days = mod_daystart - 1461 * temp_4cycles - 365 * temp_inner_years
|
|
|
|
|
|
+ temp_timeVars['inner_days'] = temp_timeVars['mod_daystart'] - 1461 * temp_timeVars['4cycles'] - 365 * temp_timeVars['inner_years']
|
|
|
|
|
|
- temp_leapyear = 0
|
|
|
|
|
|
+ temp_timeVars['leapyear'] = 0
|
|
if ((dateVars['year'] mod 4) = 0 and (dateVars['year'] mod 100) ! 0) or (dateVars['year'] mod 400 = 0):
|
|
if ((dateVars['year'] mod 4) = 0 and (dateVars['year'] mod 100) ! 0) or (dateVars['year'] mod 400 = 0):
|
|
- if temp_inner_days > 59:
|
|
|
|
- temp_inner_days -= 1
|
|
|
|
- temp_leapyear = 1
|
|
|
|
|
|
+ if temp_timeVars['inner_days'] > 59:
|
|
|
|
+ temp_timeVars['inner_days'] -= 1
|
|
|
|
+ temp_timeVars['leapyear'] = 1
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
!temp_inner_days starts at 0!
|
|
!temp_inner_days starts at 0!
|
|
- if temp_inner_days < 31:
|
|
|
|
|
|
+ if temp_timeVars['inner_days'] < 31:
|
|
dateVars['month'] = 1
|
|
dateVars['month'] = 1
|
|
- elseif temp_inner_days < 59:
|
|
|
|
|
|
+ elseif temp_timeVars['inner_days'] < 59:
|
|
dateVars['month'] = 2
|
|
dateVars['month'] = 2
|
|
- temp_inner_days -= 31
|
|
|
|
- temp_inner_days += temp_leapyear
|
|
|
|
- elseif temp_inner_days < 90:
|
|
|
|
|
|
+ temp_timeVars['inner_days'] -= 31
|
|
|
|
+ temp_timeVars['inner_days'] += temp_timeVars['leapyear']
|
|
|
|
+ elseif temp_timeVars['inner_days'] < 90:
|
|
dateVars['month'] = 3
|
|
dateVars['month'] = 3
|
|
- temp_inner_days -= 59
|
|
|
|
- elseif temp_inner_days < 120:
|
|
|
|
|
|
+ temp_timeVars['inner_days'] -= 59
|
|
|
|
+ elseif temp_timeVars['inner_days'] < 120:
|
|
dateVars['month'] = 4
|
|
dateVars['month'] = 4
|
|
- temp_inner_days -= 90
|
|
|
|
- elseif temp_inner_days < 151:
|
|
|
|
|
|
+ temp_timeVars['inner_days'] -= 90
|
|
|
|
+ elseif temp_timeVars['inner_days'] < 151:
|
|
dateVars['month'] = 5
|
|
dateVars['month'] = 5
|
|
- temp_inner_days -= 120
|
|
|
|
- elseif temp_inner_days < 181:
|
|
|
|
|
|
+ temp_timeVars['inner_days'] -= 120
|
|
|
|
+ elseif temp_timeVars['inner_days'] < 181:
|
|
dateVars['month'] = 6
|
|
dateVars['month'] = 6
|
|
- temp_inner_days -= 151
|
|
|
|
- elseif temp_inner_days < 212:
|
|
|
|
|
|
+ temp_timeVars['inner_days'] -= 151
|
|
|
|
+ elseif temp_timeVars['inner_days'] < 212:
|
|
dateVars['month'] = 7
|
|
dateVars['month'] = 7
|
|
- temp_inner_days -= 181
|
|
|
|
- elseif temp_inner_days < 243:
|
|
|
|
|
|
+ temp_timeVars['inner_days'] -= 181
|
|
|
|
+ elseif temp_timeVars['inner_days'] < 243:
|
|
dateVars['month'] = 8
|
|
dateVars['month'] = 8
|
|
- temp_inner_days -= 212
|
|
|
|
- elseif temp_inner_days < 273:
|
|
|
|
|
|
+ temp_timeVars['inner_days'] -= 212
|
|
|
|
+ elseif temp_timeVars['inner_days'] < 273:
|
|
dateVars['month'] = 9
|
|
dateVars['month'] = 9
|
|
- temp_inner_days -= 243
|
|
|
|
- elseif temp_inner_days < 304:
|
|
|
|
|
|
+ temp_timeVars['inner_days'] -= 243
|
|
|
|
+ elseif temp_timeVars['inner_days'] < 304:
|
|
dateVars['month'] = 10
|
|
dateVars['month'] = 10
|
|
- temp_inner_days -= 273
|
|
|
|
- elseif temp_inner_days < 334:
|
|
|
|
|
|
+ temp_timeVars['inner_days'] -= 273
|
|
|
|
+ elseif temp_timeVars['inner_days'] < 334:
|
|
dateVars['month'] = 11
|
|
dateVars['month'] = 11
|
|
- temp_inner_days -= 304
|
|
|
|
|
|
+ temp_timeVars['inner_days'] -= 304
|
|
else
|
|
else
|
|
dateVars['month'] = 12
|
|
dateVars['month'] = 12
|
|
- temp_inner_days -= 334
|
|
|
|
|
|
+ temp_timeVars['inner_days'] -= 334
|
|
end
|
|
end
|
|
$dateVars['month_text'] = $monthName[dateVars['month']]
|
|
$dateVars['month_text'] = $monthName[dateVars['month']]
|
|
|
|
|
|
- dateVars['day'] = 1 + temp_inner_days
|
|
|
|
|
|
+ dateVars['day'] = 1 + temp_timeVars['inner_days']
|
|
|
|
|
|
dateVars['odd_week'] = ((mod_daystart + 8) / 7) mod 2
|
|
dateVars['odd_week'] = ((mod_daystart + 8) / 7) mod 2
|
|
|
|
|
|
@@ -143,18 +149,15 @@ if $ARGS[0] = 'to_date':
|
|
'new_week: <<dateVars[''week'']>> | old_week: <<week>>'
|
|
'new_week: <<dateVars[''week'']>> | old_week: <<week>>'
|
|
'new_odd_week: <<dateVars[''odd_week'']>> | old_odd_week: <<odd_week>>'
|
|
'new_odd_week: <<dateVars[''odd_week'']>> | old_odd_week: <<odd_week>>'
|
|
*nl
|
|
*nl
|
|
- 'mod_daystart: <<mod_daystart>>'
|
|
|
|
- 'temp_inner_days: <<temp_inner_days>>'
|
|
|
|
- 'temp_leapyear: <<temp_leapyear>>'
|
|
|
|
- 'temp_4cycles: <<temp_4cycles>>'
|
|
|
|
- 'temp_inner_years: <<temp_inner_years>>'
|
|
|
|
|
|
+ 'Temp:'
|
|
|
|
+ 'mod_daystart: <<temp_timeVars[''mod_daystart'']>>'
|
|
|
|
+ 'inner_days: <<temp_timeVars[''inner_days'']>>'
|
|
|
|
+ 'leapyear: <<temp_timeVars[''leapyear'']>>'
|
|
|
|
+ '4cycles: <<temp_timeVars[''4cycles'']>>'
|
|
|
|
+ 'inner_years: <<temp_timeVars[''inner_years'']>>'
|
|
end
|
|
end
|
|
|
|
|
|
- killvar 'temp_inner_days'
|
|
|
|
- killvar 'temp_leapyear'
|
|
|
|
- killvar 'temp_4cycles'
|
|
|
|
- killvar 'temp_inner_years'
|
|
|
|
- killvar 'mod_daystart'
|
|
|
|
|
|
+ killvar 'temp_timeVars'
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
@@ -196,6 +199,115 @@ if $ARGS[0] = 'to_daystart':
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
+if $ARGS[0] = 'update_daystage':
|
|
|
|
+ if arrsize('ARGS') = 1: ARGS[1] = year
|
|
|
|
+ if arrsize('ARGS') = 2: ARGS[2] = month
|
|
|
|
+ if arrsize('ARGS') = 3: ARGS[3] = day
|
|
|
|
+ if arrsize('ARGS') = 4: ARGS[4] = hour
|
|
|
|
+ if arrsize('ARGS') = 5: ARGS[5] = minut
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ DayLength = func('time', 'get_DayLength', ARGS[1], ARGS[2], ARGS[3])
|
|
|
|
+
|
|
|
|
+ CurTimeSun = func('time', 'get_CurTimeSun', ARGS[4], ARGS[5])
|
|
|
|
+
|
|
|
|
+ ! 1 - dawn
|
|
|
|
+ ! 2 - midday
|
|
|
|
+ ! 3 - sunset
|
|
|
|
+ ! 4 - the beginning of the night
|
|
|
|
+ ! 5 - night
|
|
|
|
+ ! 6 - the end of the night
|
|
|
|
+ !! phases 1, 3, 4 and 6 last for 64 minutes
|
|
|
|
+ if CurTimeSun < -DayLength - 64:
|
|
|
|
+ DayStage = 5
|
|
|
|
+
|
|
|
|
+ BColorBase = 0 & ! Black
|
|
|
|
+ elseif CurTimeSun < -DayLength:
|
|
|
|
+ DayStage = 6
|
|
|
|
+
|
|
|
|
+ ! CurTimeSun - negative
|
|
|
|
+ ! result = 128 - [64 -> 0] * 2
|
|
|
|
+ BColorBase = 128 + (DayLength + CurTimeSun) * 2
|
|
|
|
+ elseif CurTimeSun < -DayLength + 64:
|
|
|
|
+ DayStage = 1
|
|
|
|
+
|
|
|
|
+ ! CurTimeSun - negative
|
|
|
|
+ ! result = 128 + [0 -> 64] * 2
|
|
|
|
+ BColorBase = 128 + (DayLength + CurTimeSun) * 2
|
|
|
|
+ elseif CurTimeSun < DayLength - 64:
|
|
|
|
+ DayStage = 2
|
|
|
|
+
|
|
|
|
+ BColorBase = 255 & ! White
|
|
|
|
+ elseif CurTimeSun < DayLength:
|
|
|
|
+ DayStage = 3
|
|
|
|
+
|
|
|
|
+ ! CurTimeSun - positive
|
|
|
|
+ ! result = 128 + [64 -> 0] * 2
|
|
|
|
+ BColorBase = 128 + (DayLength - CurTimeSun) * 2
|
|
|
|
+ elseif CurTimeSun < DayLength + 64:
|
|
|
|
+ DayStage = 4
|
|
|
|
+
|
|
|
|
+ ! CurTimeSun - positive
|
|
|
|
+ ! result = 128 - [0 -> 64] * 2
|
|
|
|
+ BColorBase = 128 + (DayLength - CurTimeSun) * 2
|
|
|
|
+ else
|
|
|
|
+ DayStage = 5
|
|
|
|
+
|
|
|
|
+ BColorBase = 0 & ! Black
|
|
|
|
+ end
|
|
|
|
+end
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+if $ARGS[0] = 'get_DayLength':
|
|
|
|
+ if arrsize('ARGS') = 1: ARGS[1] = year
|
|
|
|
+ if arrsize('ARGS') = 2: ARGS[2] = month
|
|
|
|
+ if arrsize('ARGS') = 3: ARGS[3] = day
|
|
|
|
+
|
|
|
|
+ ! half of daylight duration
|
|
|
|
+ ! used as an offset for solar noon
|
|
|
|
+ ! to get time when day starts and ends
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ temp_timeVars['doy_N1'] = 275 * ARGS[2] / 9
|
|
|
|
+ temp_timeVars['doy_N2'] = (ARGS[2] + 9) / 12
|
|
|
|
+ temp_timeVars['doy_N3'] = 1 + (ARGS[1] - 4 * (ARGS[1] / 4) + 2) / 3
|
|
|
|
+ temp_timeVars['DayInYear'] = temp_timeVars['doy_N1'] - (temp_timeVars['doy_N2'] * temp_timeVars['doy_N3']) + ARGS[3] - 30
|
|
|
|
+
|
|
|
|
+ temp_timeVars['DayLengthMin'] = 177 & ! Minutes from dawn to noon
|
|
|
|
+ temp_timeVars['DayLengthMax'] = 563
|
|
|
|
+
|
|
|
|
+ !! distance from summer solstice (longest day of the year)
|
|
|
|
+ if temp_timeVars['DayInYear'] < 172:
|
|
|
|
+ temp_timeVars['DayInYear2'] = 172 - temp_timeVars['DayInYear']
|
|
|
|
+ elseif temp_timeVars['DayInYear'] < 355:
|
|
|
|
+ temp_timeVars['DayInYear2'] = temp_timeVars['DayInYear'] - 172
|
|
|
|
+ else
|
|
|
|
+ temp_timeVars['DayInYear2'] = 536 - temp_timeVars['DayInYear']
|
|
|
|
+ end
|
|
|
|
+
|
|
|
|
+ result = temp_timeVars['DayLengthMax'] - ((temp_timeVars['DayLengthMax'] - temp_timeVars['DayLengthMin']) * temp_timeVars['DayInYear2']) / 182
|
|
|
|
+
|
|
|
|
+ killvar 'temp_timeVars'
|
|
|
|
+end
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+if $ARGS[0] = 'get_CurTimeSun':
|
|
|
|
+ if arrsize('ARGS') = 1: ARGS[1] = hour
|
|
|
|
+ if arrsize('ARGS') = 2: ARGS[2] = minut
|
|
|
|
+
|
|
|
|
+ ! solar noon coincides with CurTimeSun of 0 which happens at 13:00
|
|
|
|
+ !! Solar Noon (13:00) minus DayLength - time when day starts
|
|
|
|
+ !! Solar Noon (13:00) plus DayLength - time when day ends
|
|
|
|
+
|
|
|
|
+ !! distance from 13:00 (Solar Noon) in minutes
|
|
|
|
+ ! at midnight its -780
|
|
|
|
+ ! 0 is 13:00
|
|
|
|
+ ! 1 minute before midnight (23:59) is 659
|
|
|
|
+
|
|
|
|
+ result = (ARGS[1] - 13) * 60 + ARGS[2]
|
|
|
|
+end
|
|
|
|
+
|
|
|
|
+
|
|
if $ARGS[0] = 'get_time_string':
|
|
if $ARGS[0] = 'get_time_string':
|
|
if arrsize('$ARGS') = 1: ARGS[1] = hour
|
|
if arrsize('$ARGS') = 1: ARGS[1] = hour
|
|
if arrsize('$ARGS') = 2: ARGS[2] = minut
|
|
if arrsize('$ARGS') = 2: ARGS[2] = minut
|
|
@@ -204,7 +316,6 @@ if $ARGS[0] = 'get_time_string':
|
|
if ARGS[3] = 0:
|
|
if ARGS[3] = 0:
|
|
$result = '<<$mid(100 + ARGS[1], 2, 2)>>:<<$mid(100 + ARGS[2], 2, 2)>>'
|
|
$result = '<<$mid(100 + ARGS[1], 2, 2)>>:<<$mid(100 + ARGS[2], 2, 2)>>'
|
|
else
|
|
else
|
|
- $dateVars['period']
|
|
|
|
$dateVars['period'] = 'AM'
|
|
$dateVars['period'] = 'AM'
|
|
if ARGS[1] >= 12:
|
|
if ARGS[1] >= 12:
|
|
$dateVars['period'] = 'PM'
|
|
$dateVars['period'] = 'PM'
|
|
@@ -257,8 +368,10 @@ if $ARGS[0] = 'init_weeknames':
|
|
end
|
|
end
|
|
|
|
|
|
if $ARGS[0] = 'init_monthends':
|
|
if $ARGS[0] = 'init_monthends':
|
|
|
|
+ if arrsize('ARGS') = 1: ARGS[1] = year
|
|
|
|
+
|
|
monthsend[1] = 31
|
|
monthsend[1] = 31
|
|
- if ((year mod 4 = 0) and (year mod 100 ! 0)) or (year mod 400 = 0):
|
|
|
|
|
|
+ if ((ARGS[1] mod 4 = 0) and (ARGS[1] mod 100 ! 0)) or (ARGS[1] mod 400 = 0):
|
|
monthsend[2] = 29
|
|
monthsend[2] = 29
|
|
else
|
|
else
|
|
monthsend[2] = 28
|
|
monthsend[2] = 28
|
|
@@ -287,4 +400,5 @@ end
|
|
|
|
|
|
if mid($ARGS[0], 1, 2) ! 'to': killvar 'dateVars'
|
|
if mid($ARGS[0], 1, 2) ! 'to': killvar 'dateVars'
|
|
|
|
|
|
|
|
+
|
|
--- time ---------------------------------
|
|
--- time ---------------------------------
|