All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.azure.servicebus.management.SerializerUtil Maven / Gradle / Ivy

Go to download

Java library for Azure Service Bus. Please note, a newer package com.azure:azure-messaging-servicebus for Azure Service Bus is available as of December 2020. While this package will continue to receive critical bug fixes, we strongly encourage you to upgrade. Read the migration guide at https://aka.ms/azsdk/java/migrate/sb for more details.

There is a newer version: 3.6.7
Show newest version
package com.microsoft.azure.servicebus.management;

import java.time.Duration;

// Fields that require special serializations
public class SerializerUtil {
    
    public static String serializeDuration(Duration duration)
    {
        if(duration == null || duration.isNegative() || duration.isZero())
        {
            return "";
        }
        Duration remainingTime = duration;
        StringBuffer sb = new StringBuffer("P");
        long days = remainingTime.toDays();
        if(days > 0)
        {
            sb.append(days).append("D");
            remainingTime = duration.minusDays(days);
        }
        if(!remainingTime.isZero())
        {
            sb.append("T");
            long hours = remainingTime.toHours();
            if(hours > 0)
            {
                sb.append(hours).append("H");
                remainingTime = duration.minusHours(hours);
            }
            
            long minutes = remainingTime.toMinutes();
            if(minutes > 0)
            {
                sb.append(minutes).append("M");
                remainingTime = duration.minusMinutes(minutes);
            }
            
            long seconds = remainingTime.getSeconds();
            if(seconds > 0)
            {
                sb.append(seconds).append("S");
            }
        }
        
        return sb.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy