Module: Jekyll::CurrentTerm

Defined in:
jekyll/_plugins/current-term.rb

Instance Method Summary collapse

Instance Method Details

#academicYear(offset_in_years) ⇒ Object



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
# File 'jekyll/_plugins/current-term.rb', line 574

def academicYear (offset_in_years)
    # input offset in years
    # return name in yyyy
    # where first year is year of fall term, second year is year of following summer term
    # if wall clock year is March 2015 (spring term)
    # academicYearName(0) => 2014
    # academicYearName(1) => 2015
    # academicYearName(-1) => 2013
    
    site = @context.registers[:site]
    terms = site.data['univ']['fsu-terms']
    
    # get the current term
    terms.each do |key, term|
    
        if term["appt_start_date"]
            next_term = terms[term["next_term"]]
            
 #           Jekyll.logger.warn "Next Term status #{term['next_term']} : No Last Term "

            # find the current term
            if  Date.parse(term["appt_start_date"]) <= Date.today and Date.today < Date.parse(next_term["appt_start_date"])
            
                term_name = term["name"]
                year = Integer(term["year"])
                                        
                    if (term_name == 'spring') 
                        start_year = year - 1;
                    elsif (term_name == 'summer') 
                        start_year = year - 1;
                    elsif (term_name == 'fall') 
                        start_year = year ;
                    end
                    
    
 #           Jekyll.logger.warn "academicYear offset_in_years = #{offset_in_years}"

                    
                    start_year += offset_in_years.to_i;
                    
 #           Jekyll.logger.warn "academicYear start_year = #{start_year}"

                    
                    return "#{"%d" % [start_year]}"  
                
            end
        end
    end
    return "#{"%d" % [1999]}"

end

#academicYearName(offset_in_years) ⇒ Object



626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
# File 'jekyll/_plugins/current-term.rb', line 626

def academicYearName(offset_in_years)
    
    # input offset in years
    # return name in string in yyyy-yyyy format
    # where first year is year of fall term, second year is year of following summer term
    # if wall clock year is March 2015 (spring term)
    # academicYearName(0) => 2014-2015
    # academicYearName(1) => 2015-2016
    # academicYearName(-1) => 2013-2014
    
    
    start_year_string = academicYear(offset_in_years)
    start_year = start_year_string.to_i
    end_year = start_year + 1
    
    
    
    return "#{"%d - %d" % [start_year, end_year]}"  
    

end

#academicYearOfTermKey(input_term_key, offset) ⇒ Object



648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
# File 'jekyll/_plugins/current-term.rb', line 648

def academicYearOfTermKey(input_term_key,offset) 
  
 #  given a term key eg. 2020_spring, return the academic year eg 2019 + the offset
 # 2019_fall -> 2019 + offset
 # 2020_spring -> 2019 + offset
 # 2020_summer -> 2019 + offset
 
  term_array = Array["spring","summer","fall"]

  term_parts = input_term_key.split("_")
  
  year = term_parts[0]
  term = term_parts[1]
  
  if (term != "fall") 
       year = year - 1
  end

  return (year + offset)

end

#compareDateToCurrentTerm(input_date_string) ⇒ Object



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
# File 'jekyll/_plugins/current-term.rb', line 463

def compareDateToCurrentTerm(input_date_string)
    
    # input_date_string is date in mm/dd/yyyy format
    # return -1 if date prior to start of current term
    # return 0 if date within current term
    # return 1 if date after end of current term
    
    site = @context.registers[:site]
    terms = site.data['univ']['fsu-terms']
    
    
    input_date = Date.strptime(input_date_string, "%m/%d/%Y")

    
    # get the current term
    thisTerm == terms.first
    terms.each do |key, term|
        if term["appt_start_date"]
        
            next_term = terms[term["next_term"]]
            # find the current term
            if  Date.parse(term["appt_start_date"]) <= Date.today and Date.today < Date.parse(next_term["appt_start_date"])
                
                #compare input date to start and end dates of the current term
                if input_date < Date.parse(term["appt_start_date"])
                    return -1
                    elsif input_date >= Date.parse(next_term["appt_start_date"])
                    return 1
                end
                
                return 0

            end
        end
    end
    
    return -2
    
end

#compareDateToTerm(input_date_string, term_key) ⇒ Object



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
# File 'jekyll/_plugins/current-term.rb', line 503

def compareDateToTerm(input_date_string,term_key)
    
    # input_date_string is date in mm/dd/yyyy format
    # term_key is e.g. "2016_spring" to index into fsu-terms.json
    # return -1 if date prior to start of current term
    # return 0 if date within current term
    # return 1 if date after end of current term
    
    site = @context.registers[:site]
    terms = site.data['univ']['fsu-terms']
    
    input_date = Date.strptime(input_date_string, "%m/%d/%Y")

    term = terms[term_key]
    next_term = terms[term["next_term"]]
    
    # get the term start and end dates, and make comparison with the given date
    if term["appt_start_date"]
        if input_date < Date.parse(term["appt_start_date"])
            return -1
        elsif input_date >= Date.parse(next_term["appt_start_date"])
            return 1
        end
        return 0
    end
    return -2
end

#currentTermCode(offset_in_terms) ⇒ Object



382
383
384
385
386
387
388
389
# File 'jekyll/_plugins/current-term.rb', line 382

def currentTermCode(offset_in_terms) 
    # pass in offset in offset_in_terms
    # e.g. {{ 0 | currentTermCode}}
    # terms are retrieved from site.data.univ.fsu-terms json
    # return term in FSU GST term format, e.g. Fall 2016 -> "2016/9"
    term_key = currentTermKey(offset_in_terms)
    return termCodeFromKey(term_key)
end

#currentTermKey(offset_in_terms) ⇒ Object



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
# File 'jekyll/_plugins/current-term.rb', line 84

def currentTermKey(offset_in_terms)
    # pass in offset in offset_in_terms
    # return term as key (<yyyy>_<term> 
    # terms are retrieved from site.data.univ.fsu-terms json
    # e.g. if clock date is March 2015 (spring term)
    # {{ 0 | currentTermKey }} => 2015_spring
    # {{ -1 | currentTermKey }} => 2014_fall
    # {{ 1 | currentTermKey }} => 2015_summer
    if (offset_in_terms.nil?)
       return nil
    end       

    site = @context.registers[:site]
    terms = site.data['univ']['fsu-terms']
    
    base_term_name = "termstring"
    base_term_year = 1
    
    term_array = Array["spring","summer","fall"]
    
    terms.each do |key, term|
        if term["appt_start_date"]
            if  Date.parse(term["appt_start_date"]) <= Date.today
                base_term_name = term["name"]
                base_term_year = Integer(term["year"])
            end
        end
    end
    
   term_index = (base_term_year * 3) + term_array.find_index(base_term_name)
   new_term_index = (term_index + offset_in_terms.to_i)
   term_year = new_term_index.fdiv(3.0).floor
   term_name = term_array[(new_term_index % 3)]
       
   "#{"%d_%s" % [term_year,term_name]}"
      

end

#currentTermName(offset_in_terms) ⇒ Object



374
375
376
377
378
379
380
# File 'jekyll/_plugins/current-term.rb', line 374

def currentTermName(offset_in_terms)

    term_key = currentTermKey(offset_in_terms)
    
    return termNameFromKey(term_key)

end

#dateToExtapolatedTermKey(input_date_string) ⇒ Object



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
# File 'jekyll/_plugins/current-term.rb', line 30

def dateToExtapolatedTermKey(input_date_string)
        # given a date string m/d/Y
        # extrapolate to a term based on generic start/end dates
        # and return a term_key eg. 1999_summer
        # fall: August 26 - December 14
        # spring: January 7 - May 1
        # summer: May 15 - August 12
    if (input_date_string.nil?)
       return nil
    end     
        
    values = input_date_string.split("/");
    
    term_year = values[2].to_i;
    month = values[0].to_i;
    day = values[1].to_i;
    
    if (month > 8) 
        term_name = "fall"
    elsif (month == 8 && day >= 26)
        term_name = "fall"
    elsif (month > 5)
        term_name = "summer"
    elsif (month == 5 && day >= 1)
        term_name = "summer"
    elsif (month > 1)
        term_name = "spring"
    elsif (month == 1 && day >= 7)
        term_name = "spring"
    else
        term_name = "fall"
        term_year = term_year - 1;
    end

     "#{"%d_%s" % [term_year,term_name]}"
        
end

#keyFromYearAndTerm(year, term) ⇒ Object



727
728
729
730
731
732
733
# File 'jekyll/_plugins/current-term.rb', line 727

def keyFromYearAndTerm(year,term) 
    # e.g. (2017,"fall") -> "2017_fall"
    y = year.to_i
    return "#{"%d_%s" % [y, term]}" 


end

#termCodeFromKey(term_key) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'jekyll/_plugins/current-term.rb', line 168

def termCodeFromKey(term_key) 
    # e.g. "2016_fall" -> "2016/9"
    if (term_key.nil? || term_key.length < 9)
       return nil
    end       
    values = term_key.split("_")
    year = values[0]
    month = 1
    if (values[1] == 'spring') 
        month = 1
    elsif (values[1] == 'summer') 
        month = 6
    
    elsif (values[1] == 'fall') 
        month = 9
    end
    
    "#{"%d/%d" % [year,month]}"        
end

#termCodeOccursWithinTermCodes(test_code, start_code, end_code) ⇒ Object



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
# File 'jekyll/_plugins/current-term.rb', line 307

def termCodeOccursWithinTermCodes(test_code,start_code,end_code)
    # check if given test code falls within the start and end codes
    # returns true if test_code >= start_code or test_code <= end_code
    # if end_code is NULL, then assume that end_code has not occured yet (so set to 3000/1)
    # e.g. test_code = 2016/9, start_code = 2015/1, end_code = 2017/6 => true
    

    values = test_code.split("/")
    test_year = Integer(values[0])
    test_term = 0
    if (values[1] == '1') 
        test_term = 0
    elsif (values[1] == '6') 
        test_term = 1
    elsif (values[1] == '9') 
        test_term = 2
    end

    values = start_code.split("/")
    start_year = Integer(values[0])
    start_term = 0
    if (values[1] == '1') 
        start_term = 0
    elsif (values[1] == '6') 
        start_term = 1
    elsif (values[1] == '9') 
        start_term = 2
    end
    
    if (end_code != nil)
        values = end_code.split("/")
        end_year = Integer(values[0])
        end_term = 0
        if (values[1] == '1') 
            end_term = 0
        elsif (values[1] == '6') 
            end_term = 1
        elsif (values[1] == '9') 
            end_term = 2
        end
    else
        # no end code, so set in far future
        end_year = 3000
        end_term = 1
    end
    
    start_time = (start_year * 3) + start_term
    end_time = (end_year * 3) + end_term
    test_time = (test_year * 3) + test_term


   after_start = start_time <= test_time
   before_end = test_time <= end_time
   
   if (after_start && before_end)
       # Jekyll.logger.warn "termCodeOccursWithinTermCodes TRUE start = #{start_time} test = #{test_time} end =  #{end_time}"
        return true
   end
     # Jekyll.logger.warn "termCodeOccursWithinTermCodes FALSE start = #{start_time} test = #{test_time} end =  #{end_time}"
   return false

end

#termFromTermKey(term_key) ⇒ Object



76
77
78
79
80
81
82
# File 'jekyll/_plugins/current-term.rb', line 76

def termFromTermKey(term_key)
    if (term_key.nil? || term_key.length < 9)
       return nil
    end     
    values = term_key.split("_")
    term = values[1]
end

#termKeyFromCode(term_code) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'jekyll/_plugins/current-term.rb', line 212

def termKeyFromCode(term_code) 
    # e.g. "2016/9" -> "2016_fall"
    if (term_code.nil? || term_code.length < 5)
       return nil
    end            
    values = term_code.split("/")
    
    year = values[0]
     term = 'spring'
     
    if (values[1] == '1') 
        term = 'spring'
    elsif (values[1] == '6') 
        term = 'summer'
    
    elsif (values[1] == '9') 
        term = 'fall'
    end
    
   "#{"%d_%s" % [year,term]}"

end

#termKeyFromDate(input_date_string) ⇒ Object



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
# File 'jekyll/_plugins/current-term.rb', line 531

def termKeyFromDate(input_date_string)
    # input_date_string is date in mm/dd/yyyy format
    # returns term_key is e.g. "3/13/2016" -> "2016_spring" based on position within fsu-terms.json
    # uses term begin begin_date and begin_date of next term, if available
    # if no next_term, then uses end_date of this term (which may miss a weekend)
    
    site = @context.registers[:site]
    terms = site.data['univ']['fsu-terms']
    
    term_key = nil
    input_date = Date.strptime(input_date_string, "%m/%d/%Y")
    
    # Jekyll.logger.warn "input_date_string #{input_date_string} "

    # check if before the first term in our file
    key, term = terms.first
    if input_date < Date.parse(term["begin_date"])
        return dateToExtapolatedTermKey(input_date_string)
    end
    
    # check if after last term in our file
    term = terms[terms.keys.last]
    if input_date >= Date.parse(term["end_date"])
        return dateToExtapolatedTermKey(input_date_string)
    end

    terms.each do |key, term| 
            if (terms[term["next_term"]] != nil)
                end_of_term = terms[term["next_term"]]["begin_date"]
            else
                end_of_term = term["end_date"]
            end
            # Jekyll.logger.warn "begin_date #{term["begin_date"]}"
            # Jekyll.logger.warn "end_of_term #{end_of_term}"


            if input_date >= Date.parse(term["begin_date"]) && input_date < Date.parse(end_of_term)
                    term_key = key
                    return "#{term_key}"
            end
    end
end

#termKeyPlusTerms(term_key, offset_in_terms) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'jekyll/_plugins/current-term.rb', line 136

def termKeyPlusTerms(term_key,offset_in_terms)

    term_year = yearFromTermKey(term_key)
    term_name = termFromTermKey(term_key)
    
    full_years = (offset_in_terms / 3).to_i
    left_over_terms = (offset_in_terms.to_i % 3)
    
    term_year += full_years
    
    terms = Array['spring', 'summer','fall', 'spring','summer','fall']
    
    term_index = terms.index(term_name) + left_over_terms
    term_name = terms[term_index]
    
    if term_index >= 3
       term_year += 1
    end
    
   "#{"%d_%s" % [term_year,term_name]}"


end

#termKeyPlusYears(term_key, offset_in_years) ⇒ Object



125
126
127
128
129
130
131
132
133
134
# File 'jekyll/_plugins/current-term.rb', line 125

def termKeyPlusYears(term_key,offset_in_years)

    term_year = yearFromTermKey(term_key)
    term_name = termFromTermKey(term_key)
    term_year += offset_in_years;
   
   "#{"%d_%s" % [term_year,term_name]}"


end

#termNameFromCode(term_code) ⇒ Object



235
236
237
238
# File 'jekyll/_plugins/current-term.rb', line 235

def termNameFromCode(term_code)
    # e.g. 2017/9 -> "Fall 2017"
    termNameFromKey(termKeyFromCode(term_code))
end

#termNameFromKey(term_key) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'jekyll/_plugins/current-term.rb', line 188

def termNameFromKey(term_key) 
    # e.g. "2016_fall" -> "Fall 2016"
    if (term_key.nil? || term_key.length < 9)
       return nil
    end            
    values = term_key.split("_")
    year = values[0]
    term = "Spring"

    if (values[1] == 'spring') 
        term = "Spring"
    elsif (values[1] == 'summer') 
        term = "Summer"
    elsif (values[1] == 'fall') 
        term = "Fall"
    end
    
    "#{"%s %d" % [term, year]}"  

end

#termNumberBetweenTermCodes(test_code, ref_code) ⇒ Object



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
# File 'jekyll/_plugins/current-term.rb', line 270

def termNumberBetweenTermCodes(test_code,ref_code)
    # number of terms between the test_code term and the ref_code term ( including the test_code term, but not the ref code term)
    # ref_code can be prior to test_code, or after the test code
    
    # e.g. (2015/9, 2016/9) -> 3 terms (i.e. 2015/9, 2016/1, and 2016/6)
    # e.g. (2015/6, 2014/9) -> 2 terms (i.e. 2015/1, 2015/6)
    
    
    values = test_code.split("/")
    year1 = Integer(values[0])
    term1 = 0
    if (values[1] == '1') 
        term1 = 0
    elsif (values[1] == '6') 
        term1 = 1
    elsif (values[1] == '9') 
        term1 = 2
    end

    values = ref_code.split("/")
    year2 = Integer(values[0])
    term2 = 0
    if (values[1] == '1') 
        term2 = 0
    elsif (values[1] == '6') 
        term2 = 1
    elsif (values[1] == '9') 
        term2 = 2
    end
    
   terms_between = ((year1 * 3) + term1) - ((year2 * 3) + term2)
    
    "#{"%d" % [terms_between]}"
   

end

#termOfAcademicYearAsCode(input_term, acad_year, year_offset) ⇒ Object



713
714
715
716
717
718
# File 'jekyll/_plugins/current-term.rb', line 713

def termOfAcademicYearAsCode(input_term,acad_year,year_offset)

    term_key = termOfAcademicYearAsKey(input_term,acad_year,year_offset)
    termCodeFromKey(term_key)

end

#termOfAcademicYearAsKey(input_term, acad_year, year_offset) ⇒ Object



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
# File 'jekyll/_plugins/current-term.rb', line 671

def termOfAcademicYearAsKey(input_term,acad_year,year_offset)
    # pass in name of desired term (fall, spring, or summer) in input_term, with year_offset from given academic year in years
    # returns termKey for the academic year
    # e.g. {{ "spring" | termOfAcademicYearAsKey:2016, 1 }}
    # return a key for that term in given academic year + year_offset
    #
    # examples if today is in fall of 2015
    #
    # "fall" |  termOfAcademicYearAsKey:2015,0 => 2015_fall
    # "spring" |  termOfAcademicYearAsKey:2015,0 => 2016_spring
    # "summer" |  termOfAcademicYearAsKey:2015,0 => 2016_summer
    #
    #
    # "fall" |  termOfAcademicYearAsKey:2015,-1 => 2014_fall
    # "spring" |  termOfAcademicYearAsKey:2015,2 => 2018_spring
    # "summer" |  termOfAcademicYearAsKey:2015,1 => 2017_summer
    #
    #
            
   # Jekyll.logger.warn "termOfAcademicYearAsKey acad_year = #{acad_year} year_offset = #{year_offset}"

    base_term_name = "termstring"
    base_term_year = 1
    term_year = 1
    
    term_array = Array["spring","summer","fall"]

    term_year = acad_year.to_i  + year_offset.to_i 
    
    if (input_term == 'fall') 
        term_year =  term_year
    elsif (input_term == 'summer' || input_term == 'spring' ) 
        term_year =  term_year + 1
    end
    
    # Jekyll.logger.warn "termOfAcademicYearAsKey #{"%d_%s" % [term_year,input_term]}"
    
    "#{"%d_%s" % [term_year,input_term]}"
       
end

#termOfAcademicYearAsName(input_term, acad_year, year_offset) ⇒ Object



720
721
722
723
724
725
# File 'jekyll/_plugins/current-term.rb', line 720

def termOfAcademicYearAsName(input_term,acad_year,year_offset)
    
    term_key = termOfAcademicYearAsKey(input_term,acad_year,year_offset)
    termNameFromKey(term_key)

end

#termOfCurrentYearAsCode(input_term, offset) ⇒ Object



447
448
449
450
451
452
# File 'jekyll/_plugins/current-term.rb', line 447

def termOfCurrentYearAsCode(input_term,offset)

    term_key = termOfCurrentYearAsKey(input_term,offset)
    termCodeFromKey(term_key)

end

#termOfCurrentYearAsKey(input_term, offset) ⇒ Object



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
# File 'jekyll/_plugins/current-term.rb', line 391

def termOfCurrentYearAsKey(input_term,offset)
    # pass in name of desired term (fall, spring, or summer) in input_term, with offset from current year in years
    # returns termKey for the academic year
    # e.g. {{ "spring" | termOfCurrentYearAsKey }}
    # return a key for that term in current academic year + offset
    #
    # examples if today is in fall of 2015
    #
    # "fall" |  termOfCurrentYearAsKey => 2015_fall
    # "spring" |  termOfCurrentYearAsKey => 2016_spring
    # "summer" |  termOfCurrentYearAsKey => 2016_summer
    #
    #
    # "fall" |  termOfCurrentYearAsKey:-1 => 2014_fall
    # "spring" |  termOfCurrentYearAsKey:2 => 2018_spring
    # "summer" |  termOfCurrentYearAsKey:1 => 2017_summer
    #
    #
            

    base_term_name = "termstring"
    base_term_year = 1
    term_year = 1
    
    term_array = Array["spring","summer","fall"]



#        Jekyll.logger.warn "termOfCurrentYearAsKey offset = #{offset}"

    base_term_year = academicYear(offset)
    term_year = base_term_year.to_i 
    
    if (input_term == 'fall') 
        term_year =  term_year
    elsif (input_term == 'summer' || input_term == 'spring' ) 
    
        term_year =  term_year + 1
        # Jekyll.logger.warn "termOfCurrentYearAsKey base_term_year = #{base_term_year} term_year  #{term_year}"

    end
       
#      Jekyll.logger.warn "termOfCurrentYearAsKey term_year = #{term_year}"


  #  if (input_term == 'summer' && offset == "-1") 
 #        Jekyll.logger.warn "termOfCurrentYearAsKey Summer -1 base_term_year = #{base_term_year} term_year  #{term_year}"
 #   end
 #   if (input_term == 'spring' && offset == "0") 
#         Jekyll.logger.warn "termOfCurrentYearAsKey Spring 0 base_term_year = #{base_term_year} term_year  #{term_year}"
#    end

    "#{"%d_%s" % [term_year,input_term]}"
end

#termOfCurrentYearAsName(input_term, offset) ⇒ Object



454
455
456
457
458
459
# File 'jekyll/_plugins/current-term.rb', line 454

def termOfCurrentYearAsName(input_term,offset)
    
    term_key = termOfCurrentYearAsKey(input_term,offset)
    termNameFromKey(term_key)

end

#unixTimeFromKey(term_key) ⇒ Object



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
# File 'jekyll/_plugins/current-term.rb', line 241

def unixTimeFromKey(term_key) 

    # e.g. "2016_fall" -> "2016/8/20" -> "1471651200"
    if (term_key.nil? || term_key.length < 9)
       return nil
    end            
    values = term_key.split("_")
    year = values[0]
    
    day = 1
    month = 1

    if (values[1] == 'spring') 
        month = 1
    elsif (values[1] == 'summer') 
        month = 5
    elsif (values[1] == 'fall') 
        month = 8
        day = 20
    end
    
   #  Date.new(year,month,day).to_time.to_i
    # 1471651200
   # "#{"%d_%d_%d" % [year,month,day]}"
    
    term_date = Time.new(year,month,day).to_i
    
end

#yearFromTermKey(term_key) ⇒ Object



68
69
70
71
72
73
74
# File 'jekyll/_plugins/current-term.rb', line 68

def yearFromTermKey(term_key)
    if (term_key.nil? || term_key.length < 9)
       return nil
    end     
    values = term_key.split("_")
    year = values[0].to_i
end