yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/jdcloud/utils.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package jdcloud 16 17 import ( 18 "time" 19 20 "github.com/jdcloud-api/jdcloud-sdk-go/services/charge/models" 21 22 billing_api "yunion.io/x/cloudmux/pkg/apis/billing" 23 ) 24 25 func parseTime(ts string) time.Time { 26 t, _ := time.Parse("2006-01-02T15:04:05Z", ts) 27 return t 28 } 29 30 func billingType(charge *models.Charge) string { 31 switch charge.ChargeMode { 32 case "prepaid_by_duration": 33 return billing_api.BILLING_TYPE_PREPAID 34 case "postpaid_by_usage", "postpaid_by_duration": 35 return billing_api.BILLING_TYPE_POSTPAID 36 default: 37 return "" 38 } 39 } 40 41 func expireAt(charge *models.Charge) time.Time { 42 if billingType(charge) == billing_api.BILLING_TYPE_POSTPAID { 43 return time.Time{} 44 } 45 return parseTime(charge.ChargeExpiredTime) 46 }