Skip to content

Instantly share code, notes, and snippets.

@elringus
Last active August 29, 2015 14:27
Show Gist options
  • Save elringus/aa1d511d005570616f0f to your computer and use it in GitHub Desktop.
Save elringus/aa1d511d005570616f0f to your computer and use it in GitHub Desktop.
Collection of various blueprint functions.
#include "Saga.h"
#include "BlueprintUtils.h"
FDateTime UBlueprintUtils::StringToDatetime(const FString& dateTimeString)
{
FString modifiedString;
dateTimeString.Split(TEXT("."), &modifiedString, nullptr);
FDateTime dateTime;
FDateTime::ParseIso8601(*modifiedString, dateTime);
return dateTime;
}
FTimespan UBlueprintUtils::StringToTimeSpan(const FString& timeSpanString)
{
FTimespan timeSpan;
FTimespan::Parse(*FString::Printf(TEXT("%s.000"), *timeSpanString), timeSpan);
return timeSpan;
}
#pragma once
#include "Kismet/BlueprintFunctionLibrary.h"
#include "BlueprintUtils.generated.h"
/**
* Collection of various blueprint functions.
*/
UCLASS()
class SAGA_API UBlueprintUtils : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
/**
* Converts an ISO-8601 formatted DateTime string to UE native DateTime struct.
* @param dateTimeString ISO-8601 compliant DateTime representation.
* @return UE native DateTime struct.
*/
UFUNCTION(BlueprintPure, Category = "Utils|Time", meta = (DisplayName = "String To DateTime"))
static FDateTime StringToDatetime(const FString& dateTimeString);
/**
* Converts a .NET TimeSpan string to UE native TimeSpan struct.
* @param timeSpanString .NET string TimeSpan representation.
* @return UE native TimeSpan struct.
*/
UFUNCTION(BlueprintPure, Category = "Utils|Time", meta = (DisplayName = "String To TimeSpan"))
static FTimespan StringToTimeSpan(const FString& timeSpanString);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment