Skip to content

Commit

Permalink
🚚restructure project🚛 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
hf-kklein authored Sep 29, 2022
1 parent 5f8975f commit ed04a04
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 28 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ jobs:
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# If you wish to specify custom queries, you can do so here or in a configuration file.
# By default, queries listed here will override any specified in a configuration file.
# Prefix the list here with "+" to use these queries and those in the configuration file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
Expand Down
4 changes: 2 additions & 2 deletions pkg/config.go → configuration/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package pkg
package configuration

import (
"github.com/go-playground/validator/v10"
"github.com/hochfrequenz/mako_time_converter/pkg/enddatetimekind"
"github.com/hochfrequenz/mako_time_converter/configuration/enddatetimekind"
)

// DateTimeConfiguration describes how a time.Time is meant/interpreted by a system. Two of these configurations allow to convert a time.Time smoothly.
Expand Down
File renamed without changes.
9 changes: 5 additions & 4 deletions pkg/gastagconverter.go → conversion/gastagconverter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package pkg
import (
"fmt"
"github.com/go-playground/validator/v10"
"github.com/hochfrequenz/mako_time_converter/pkg/enddatetimekind"
mtcconfig "github.com/hochfrequenz/mako_time_converter/configuration"
"github.com/hochfrequenz/mako_time_converter/configuration/enddatetimekind"
"log"
"time"
)
Expand All @@ -21,7 +22,7 @@ type GasTagConverter interface {
// StripTime removes all hours, minutes, seconds, milliseconds (in german local time) from the given timestamp. This is similar to a "round down" or "floor" in German local time.
StripTime(timestamp time.Time) time.Time
// Convert converts the given timestamp to a DateTimeConversionConfiguration.Target by applying all transformations which are derived from the given configuration time is described by DateTimeConversionConfiguration.Source.
Convert(timestamp time.Time, configuration DateTimeConversionConfiguration) (time.Time, error)
Convert(timestamp time.Time, configuration mtcconfig.DateTimeConversionConfiguration) (time.Time, error)
}

type locationBasedGasTagConverter struct {
Expand Down Expand Up @@ -93,9 +94,9 @@ func (l locationBasedGasTagConverter) subtractGermanDay(timestamp time.Time) tim
return localtime.AddDate(0, 0, -1).UTC()
}

func (l locationBasedGasTagConverter) Convert(timestamp time.Time, configuration DateTimeConversionConfiguration) (time.Time, error) {
func (l locationBasedGasTagConverter) Convert(timestamp time.Time, configuration mtcconfig.DateTimeConversionConfiguration) (time.Time, error) {
validate := validator.New()
validate.RegisterStructValidation(DateTimeConversionConfigurationStructLevelValidator, DateTimeConversionConfiguration{})
validate.RegisterStructValidation(mtcconfig.DateTimeConversionConfigurationStructLevelValidator, mtcconfig.DateTimeConversionConfiguration{})
err := validate.Struct(configuration)
if err != nil {
return time.Time{}, err
Expand Down
37 changes: 19 additions & 18 deletions pkg/gastagconverter_test.go → conversion/gastagconverter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package pkg_test
import (
"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
"github.com/hochfrequenz/mako_time_converter/pkg"
"github.com/hochfrequenz/mako_time_converter/pkg/enddatetimekind"
"github.com/hochfrequenz/mako_time_converter/configuration"
"github.com/hochfrequenz/mako_time_converter/configuration/enddatetimekind"
"github.com/hochfrequenz/mako_time_converter/conversion"
"github.com/stretchr/testify/suite"
"testing"
"time"
Expand Down Expand Up @@ -118,9 +119,9 @@ func (s *Suite) Test_Gastag_Aware_To_Non_Gastag_Aware() {
time.Date(2023, 6, 1, 4, 0, 0, 0, time.UTC): time.Date(2023, 5, 31, 22, 0, 0, 0, time.UTC),
time.Date(2023, 12, 1, 5, 0, 0, 0, time.UTC): time.Date(2023, 11, 30, 23, 0, 0, 0, time.UTC),
}
conversion := pkg.DateTimeConversionConfiguration{
Source: pkg.DateTimeConfiguration{IsGas: true, IsGasTagAware: pointer(true)},
Target: pkg.DateTimeConfiguration{IsGas: true, IsGasTagAware: pointer(false)},
conversion := configuration.DateTimeConversionConfiguration{
Source: configuration.DateTimeConfiguration{IsGas: true, IsGasTagAware: pointer(true)},
Target: configuration.DateTimeConfiguration{IsGas: true, IsGasTagAware: pointer(false)},
}
converter := getBerlinConverter()
for input, expected := range pairs {
Expand All @@ -143,9 +144,9 @@ func (s *Suite) Test_Strom_Inclusive_End_To_Strom_Exclusive_End() {
time.Date(2023, 12, 31, 23, 0, 0, 0, time.UTC): time.Date(2024, 01, 01, 23, 0, 0, 0, time.UTC),
time.Date(2023, 12, 01, 23, 0, 0, 0, time.UTC): time.Date(2023, 12, 02, 23, 0, 0, 0, time.UTC),
}
conversion := pkg.DateTimeConversionConfiguration{
Source: pkg.DateTimeConfiguration{IsGas: false, IsEndDate: true, EndDateTimeKind: pointer(enddatetimekind.INCLUSIVE)},
Target: pkg.DateTimeConfiguration{IsGas: false, IsEndDate: true, EndDateTimeKind: pointer(enddatetimekind.EXCLUSIVE)},
conversion := configuration.DateTimeConversionConfiguration{
Source: configuration.DateTimeConfiguration{IsGas: false, IsEndDate: true, EndDateTimeKind: pointer(enddatetimekind.INCLUSIVE)},
Target: configuration.DateTimeConfiguration{IsGas: false, IsEndDate: true, EndDateTimeKind: pointer(enddatetimekind.EXCLUSIVE)},
}
converter := getBerlinConverter()
for input, expected := range pairs {
Expand All @@ -167,9 +168,9 @@ func (s *Suite) Test_Gas_Inclusive_End_To_Gas_Exclusive_End() {
time.Date(2023, 12, 30, 05, 0, 0, 0, time.UTC): time.Date(2023, 12, 31, 05, 0, 0, 0, time.UTC),
time.Date(2023, 12, 01, 05, 0, 0, 0, time.UTC): time.Date(2023, 12, 02, 05, 0, 0, 0, time.UTC),
}
conversion := pkg.DateTimeConversionConfiguration{
Source: pkg.DateTimeConfiguration{IsGas: true, IsGasTagAware: pointer(true), IsEndDate: true, EndDateTimeKind: pointer(enddatetimekind.INCLUSIVE)},
Target: pkg.DateTimeConfiguration{IsGas: true, IsGasTagAware: pointer(true), IsEndDate: true, EndDateTimeKind: pointer(enddatetimekind.EXCLUSIVE)},
conversion := configuration.DateTimeConversionConfiguration{
Source: configuration.DateTimeConfiguration{IsGas: true, IsGasTagAware: pointer(true), IsEndDate: true, EndDateTimeKind: pointer(enddatetimekind.INCLUSIVE)},
Target: configuration.DateTimeConfiguration{IsGas: true, IsGasTagAware: pointer(true), IsEndDate: true, EndDateTimeKind: pointer(enddatetimekind.EXCLUSIVE)},
}
converter := getBerlinConverter()
for input, expected := range pairs {
Expand All @@ -186,18 +187,18 @@ func (s *Suite) Test_Gas_Inclusive_End_To_Gas_Exclusive_End() {
}

func (s *Suite) Test_Invalid_Configurations_Are_Rejected() {
invalidConfigs := []pkg.DateTimeConversionConfiguration{
invalidConfigs := []configuration.DateTimeConversionConfiguration{
{
Source: pkg.DateTimeConfiguration{IsGas: false, IsGasTagAware: pointer(true)},
Target: pkg.DateTimeConfiguration{IsGas: true, IsGasTagAware: pointer(true)},
Source: configuration.DateTimeConfiguration{IsGas: false, IsGasTagAware: pointer(true)},
Target: configuration.DateTimeConfiguration{IsGas: true, IsGasTagAware: pointer(true)},
},
{
Source: pkg.DateTimeConfiguration{IsEndDate: true}, // no enddatetime kind given
Target: pkg.DateTimeConfiguration{IsEndDate: true, EndDateTimeKind: pointer(enddatetimekind.EXCLUSIVE)},
Source: configuration.DateTimeConfiguration{IsEndDate: true}, // no enddatetime kind given
Target: configuration.DateTimeConfiguration{IsEndDate: true, EndDateTimeKind: pointer(enddatetimekind.EXCLUSIVE)},
},
{
Source: pkg.DateTimeConfiguration{IsGas: true, IsGasTagAware: pointer(true)},
Target: pkg.DateTimeConfiguration{IsGas: true}, // no gastag awareness given
Source: configuration.DateTimeConfiguration{IsGas: true, IsGasTagAware: pointer(true)},
Target: configuration.DateTimeConfiguration{IsGas: true}, // no gastag awareness given
},
}
converter := getBerlinConverter()
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/hochfrequenz/mako_time_converter => ./pkg
replace (
github.com/hochfrequenz/mako_time_converter/configuration => ./configuration
github.com/hochfrequenz/mako_time_converter/conversion => ./conversion
)

0 comments on commit ed04a04

Please sign in to comment.