Skip to content

Commit

Permalink
SONAR-5183 timezones - restore Snapshot API
Browse files Browse the repository at this point in the history
  • Loading branch information
teryk committed Feb 6, 2015
1 parent 7695be1 commit e3b0bda
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
Expand Up @@ -50,12 +50,12 @@ public Periods(Settings settings, I18n i18n) {

@CheckForNull
public String label(Snapshot snapshot, int periodIndex) {
return label(snapshot.getPeriodMode(periodIndex), snapshot.getPeriodModeParameter(periodIndex), longToDate(snapshot.getPeriodDate(periodIndex)));
return label(snapshot.getPeriodMode(periodIndex), snapshot.getPeriodModeParameter(periodIndex), longToDate(snapshot.getPeriodDateMs(periodIndex)));
}

@CheckForNull
public String abbreviation(Snapshot snapshot, int periodIndex) {
return abbreviation(snapshot.getPeriodMode(periodIndex), snapshot.getPeriodModeParameter(periodIndex), longToDate(snapshot.getPeriodDate(periodIndex)));
return abbreviation(snapshot.getPeriodMode(periodIndex), snapshot.getPeriodModeParameter(periodIndex), longToDate(snapshot.getPeriodDateMs(periodIndex)));
}

@CheckForNull
Expand Down
Expand Up @@ -63,7 +63,7 @@ public void before() {
@Test
public void label_of_duration_in_days() {
when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_DAYS);
when(snapshot.getPeriodDate(periodIndex)).thenReturn(System2.INSTANCE.now());
when(snapshot.getPeriodDateMs(periodIndex)).thenReturn(System2.INSTANCE.now());
when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param);

periods.label(snapshot, periodIndex);
Expand All @@ -73,7 +73,7 @@ public void label_of_duration_in_days() {
@Test
public void abbreviation_of_duration_in_days() {
when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_DAYS);
when(snapshot.getPeriodDate(periodIndex)).thenReturn(System.currentTimeMillis());
when(snapshot.getPeriodDateMs(periodIndex)).thenReturn(System.currentTimeMillis());
when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param);

periods.abbreviation(snapshot, periodIndex);
Expand All @@ -83,7 +83,7 @@ public void abbreviation_of_duration_in_days() {
@Test
public void label_of_snapshot_version() {
when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_VERSION);
when(snapshot.getPeriodDate(periodIndex)).thenReturn(System.currentTimeMillis());
when(snapshot.getPeriodDateMs(periodIndex)).thenReturn(System.currentTimeMillis());
when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param);

periods.label(snapshot, periodIndex);
Expand All @@ -93,7 +93,7 @@ public void label_of_snapshot_version() {
@Test
public void abbreviation_of_snapshot_version() {
when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_VERSION);
when(snapshot.getPeriodDate(periodIndex)).thenReturn(System.currentTimeMillis());
when(snapshot.getPeriodDateMs(periodIndex)).thenReturn(System.currentTimeMillis());
when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param);

periods.abbreviation(snapshot, periodIndex);
Expand All @@ -103,7 +103,7 @@ public void abbreviation_of_snapshot_version() {
@Test
public void label_of_previous_analysis_with_date() {
when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
when(snapshot.getPeriodDate(periodIndex)).thenReturn(System.currentTimeMillis());
when(snapshot.getPeriodDateMs(periodIndex)).thenReturn(System.currentTimeMillis());

periods.label(snapshot, periodIndex);
verify(i18n).message(any(Locale.class), eq("since_previous_analysis_detailed"), isNull(String.class), anyString());
Expand All @@ -112,7 +112,7 @@ public void label_of_previous_analysis_with_date() {
@Test
public void label_of_previous_analysis_without_date() {
when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
when(snapshot.getPeriodDate(periodIndex)).thenReturn(null);
when(snapshot.getPeriodDateMs(periodIndex)).thenReturn(null);
when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param);

periods.label(snapshot, periodIndex);
Expand All @@ -122,7 +122,7 @@ public void label_of_previous_analysis_without_date() {
@Test
public void abbreviation_of_previous_analysis_with_date() {
when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
when(snapshot.getPeriodDate(periodIndex)).thenReturn(System.currentTimeMillis());
when(snapshot.getPeriodDateMs(periodIndex)).thenReturn(System.currentTimeMillis());

periods.abbreviation(snapshot, periodIndex);
verify(i18n).message(any(Locale.class), eq("since_previous_analysis_detailed.short"), isNull(String.class), anyString());
Expand All @@ -131,7 +131,7 @@ public void abbreviation_of_previous_analysis_with_date() {
@Test
public void abbreviation_of_previous_analysis_without_date() {
when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
when(snapshot.getPeriodDate(periodIndex)).thenReturn(null);
when(snapshot.getPeriodDateMs(periodIndex)).thenReturn(null);
when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param);

periods.abbreviation(snapshot, periodIndex);
Expand All @@ -151,7 +151,7 @@ public void shouldReturnSnapshotLabelInModePreviousVersionWithParamNotNull() {
public void label_of_previous_version_with_param_and_date() {
when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param);
when(snapshot.getPeriodDate(periodIndex)).thenReturn(System.currentTimeMillis());
when(snapshot.getPeriodDateMs(periodIndex)).thenReturn(System.currentTimeMillis());

periods.label(snapshot, periodIndex);
verify(i18n).message(any(Locale.class), eq("since_previous_version_detailed"), isNull(String.class), eq(param), anyString());
Expand All @@ -169,7 +169,7 @@ public void shouldReturnSnapshotLabelInModePreviousVersionWithParamNull() {
@Test
public void shouldReturnSnapshotLabelInModeDate() {
when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_DATE);
when(snapshot.getPeriodDate(periodIndex)).thenReturn(System.currentTimeMillis());
when(snapshot.getPeriodDateMs(periodIndex)).thenReturn(System.currentTimeMillis());

periods.label(snapshot, periodIndex);

Expand Down
Expand Up @@ -714,6 +714,30 @@ public String getPeriodModeParameter(int periodIndex) {
*
* @since 2.5
*/
public Snapshot setPeriodDate(int periodIndex, Date date) {
Long time = dateToLong(date);
switch (periodIndex) {
case 1:
period1Date = time;
break;
case 2:
period2Date = time;
break;
case 3:
period3Date = time;
break;
case 4:
period4Date = time;
break;
case 5:
period5Date = time;
break;
default:
throw new IndexOutOfBoundsException("Index of Snapshot.periodDate is between 1 and 5");
}
return this;
}

public Snapshot setPeriodDateMs(int periodIndex, Long date) {
switch (periodIndex) {
case 1:
Expand All @@ -737,7 +761,24 @@ public Snapshot setPeriodDateMs(int periodIndex, Long date) {
return this;
}

public Long getPeriodDate(int periodIndex) {
public Date getPeriodDate(int periodIndex) {
switch (periodIndex) {
case 1:
return longToDate(period1Date);
case 2:
return longToDate(period2Date);
case 3:
return longToDate(period3Date);
case 4:
return longToDate(period4Date);
case 5:
return longToDate(period5Date);
default:
throw new IndexOutOfBoundsException("Index of Snapshot.periodDate is between 1 and 5");
}
}

public Long getPeriodDateMs(int periodIndex) {
switch (periodIndex) {
case 1:
return period1Date;
Expand Down

0 comments on commit e3b0bda

Please sign in to comment.