Groovy web console

subscribe to the feed Subscribe
to this


Published 3 weeks ago by Dimple
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.json.JsonSlurperClassic
import groovy.json.JsonParserType
import groovy.json.JsonOutput
import groovy.transform.Field
import java.text.*;
def envs = [
             "ahgr5e6rxo-dev": ["lastUpdated": "2020-09-01T13:30:31:996","created": "2020-09-01T13:30:31:994","status": "pending_archival"],"vbvonfkugx-dev": ["lastUpdated": "2020-08-26T10:43:14:189","created": "2020-08-26T10:36:38:150","status": "archived"],"old-dev": ["lastUpdated": "2020-07-26T10:43:14:189","created": "2020-07-26T10:36:38:150","status": "pending_archival"]]

def srt = sort(envs);
println "srt: ${srt}"

def sort(items) {
  println "items: $items"
    def format = "yyyy-mm-dd HH:mm:ss"
    def itemsSorted = items.sort {a, b -> 
        def val1 = a.value.created.replace("T", " ");
        def val2 = b.value.created.replace("T", " ");
        println "val1: $val1"
        println "val2: $val2" 
        def x = new SimpleDateFormat(format).parse(val1)
        def y = new SimpleDateFormat(format).parse(val2)
        println "x: $x"
        println "y: $y"
        y <=> x}
    return itemsSorted