Class: Gitlab::Ci::CronParser

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/cron_parser.rb

Constant Summary collapse

VALID_SYNTAX_SAMPLE_TIME_ZONE =
'UTC'
VALID_SYNTAX_SAMPLE_CRON =
'* * * * *'

Instance Method Summary collapse

Constructor Details

#initialize(cron, cron_timezone = 'UTC') ⇒ CronParser

Returns a new instance of CronParser.


9
10
11
12
# File 'lib/gitlab/ci/cron_parser.rb', line 9

def initialize(cron, cron_timezone = 'UTC')
  @cron = cron
  @cron_timezone = timezone_name(cron_timezone)
end

Instance Method Details

#cron_timezone_valid?Boolean

Returns:

  • (Boolean)

26
27
28
# File 'lib/gitlab/ci/cron_parser.rb', line 26

def cron_timezone_valid?
  try_parse_cron(VALID_SYNTAX_SAMPLE_CRON, @cron_timezone).present?
end

#cron_valid?Boolean

Returns:

  • (Boolean)

22
23
24
# File 'lib/gitlab/ci/cron_parser.rb', line 22

def cron_valid?
  try_parse_cron(@cron, VALID_SYNTAX_SAMPLE_TIME_ZONE).present?
end

#next_time_from(time) ⇒ Object


14
15
16
# File 'lib/gitlab/ci/cron_parser.rb', line 14

def next_time_from(time)
  cron_line.next_time(time).utc.in_time_zone(Time.zone) if cron_line.present?
end

#previous_time_from(time) ⇒ Object


18
19
20
# File 'lib/gitlab/ci/cron_parser.rb', line 18

def previous_time_from(time)
  cron_line.previous_time(time).utc.in_time_zone(Time.zone) if cron_line.present?
end