<commit_before>import ceylon.time {
    time,
    Time
}
import ceylon.time.timezone.model {
    AtTime,
    AtWallClockTime,
    AtNauticalTime,
    AtUtcTime,
    AtLocalMeanTime,
    AtGmtTime
}

"Alias to represent a specific signal:
 * Positive = 1
 * Negative = -1"
shared alias Signal => Integer;

[AtTime, Signal] parseTime(String atTime) {
    if( atTime.equals("-") ) {
        return [AtWallClockTime(time(0, 0)), 1];
    }
    value signal = atTime.startsWith("-") then -1 else 1;
    value position = atTime.startsWith("-") then 1 else 0;
    
    if(! atTime.firstOccurrence(':') exists ) {
        assert(exists hours = parseInteger(atTime.spanFrom(position)));
        return [AtWallClockTime(adjustToEndOfDayIfNecessary(hours, 0)), signal];
    }
    
    value indexes = atTime.indexesWhere(':'.equals).sequence();
    
    assert( exists firstIndex = indexes[0] );
    assert( exists hours = parseInteger(atTime.span(position, firstIndex-1)));
    assert( exists minutes = parseInteger(atTime.span(firstIndex +1,firstIndex  + 2 )));
    variable value partialTime = adjustToEndOfDayIfNecessary( hours, minutes ); 
    AtTime ruleDefinition;
    if( indexes.size == 1 ) {
        ruleDefinition = atTimeDefinition(partialTime, atTime.spanFrom(firstIndex + 3));
    } else {
        assert( exists secondIndex = indexes[1] );  
        assert( exists seconds = parseInteger(atTime.span(secondIndex + 1 ,secondIndex  + 2 ))); 
        
        partialTime = partialTime.plusSeconds(seconds);   
        ruleDefinition = atTimeDefinition(partialTime, atTime.spanFrom(secondIndex + 3));
    }
    
    return [ruleDefinition, signal];
}

AtTime atTimeDefinition(Time time, String token) {
    switch (token)
    case("s", "S") {
        return AtLocalMeanTime(time);
    }
    case("u", "U") {
        return AtUtcTime(time);
    }
    case("z", "Z") {
        return AtNauticalTime(time);
    }
    case("g", "G") {
        return AtGmtTime(time);
    }
    case("w", "W") {
        return AtWallClockTime(time);
    } 
    else {
        return AtWallClockTime(time);
    }
}

"The rules represent the end of day as 24:00 and our ceylon.time.Time 
 does have another semantic for this."
Time adjustToEndOfDayIfNecessary(Integer hours, Integer minutes) {
    if( hours == 24 && minutes == 0 ) {
        return time(23,59,59,999);
    }
    return time( hours, minutes );
}<commit_msg>fix sintax for switch using '|' instead of ','<commit_after>import ceylon.time {
    time,
    Time
}
import ceylon.time.timezone.model {
    AtTime,
    AtWallClockTime,
    AtNauticalTime,
    AtUtcTime,
    AtLocalMeanTime,
    AtGmtTime
}

"Alias to represent a specific signal:
 * Positive = 1
 * Negative = -1"
shared alias Signal => Integer;

[AtTime, Signal] parseTime(String atTime) {
    if( atTime.equals("-") ) {
        return [AtWallClockTime(time(0, 0)), 1];
    }
    value signal = atTime.startsWith("-") then -1 else 1;
    value position = atTime.startsWith("-") then 1 else 0;
    
    if(! atTime.firstOccurrence(':') exists ) {
        assert(exists hours = parseInteger(atTime.spanFrom(position)));
        return [AtWallClockTime(adjustToEndOfDayIfNecessary(hours, 0)), signal];
    }
    
    value indexes = atTime.indexesWhere(':'.equals).sequence();
    
    assert( exists firstIndex = indexes[0] );
    assert( exists hours = parseInteger(atTime.span(position, firstIndex-1)));
    assert( exists minutes = parseInteger(atTime.span(firstIndex +1,firstIndex  + 2 )));
    variable value partialTime = adjustToEndOfDayIfNecessary( hours, minutes ); 
    AtTime ruleDefinition;
    if( indexes.size == 1 ) {
        ruleDefinition = atTimeDefinition(partialTime, atTime.spanFrom(firstIndex + 3));
    } else {
        assert( exists secondIndex = indexes[1] );  
        assert( exists seconds = parseInteger(atTime.span(secondIndex + 1 ,secondIndex  + 2 ))); 
        
        partialTime = partialTime.plusSeconds(seconds);   
        ruleDefinition = atTimeDefinition(partialTime, atTime.spanFrom(secondIndex + 3));
    }
    
    return [ruleDefinition, signal];
}

AtTime atTimeDefinition(Time time, String token) {
    switch (token)
    case("s" | "S") {
        return AtLocalMeanTime(time);
    }
    case("u" | "U") {
        return AtUtcTime(time);
    }
    case("z" | "Z") {
        return AtNauticalTime(time);
    }
    case("g" | "G") {
        return AtGmtTime(time);
    }
    case("w" | "W") {
        return AtWallClockTime(time);
    } 
    else {
        return AtWallClockTime(time);
    }
}

"The rules represent the end of day as 24:00 and our ceylon.time.Time 
 does have another semantic for this."
Time adjustToEndOfDayIfNecessary(Integer hours, Integer minutes) {
    if( hours == 24 && minutes == 0 ) {
        return time(23,59,59,999);
    }
    return time( hours, minutes );
}
{'fraction_non_alphanumeric': 0.12696443341604632, 'fraction_numerical': 0.01488833746898263, 'mean_word_length': 2.9777960526315788, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6984078', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1519, 'n_words': 363}