congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Calendar.fromIso
Code IndexAdd Tabnine to your IDE (free)

How to use
fromIso
method
in
org.hisp.dhis.calendar.Calendar

Best Java code snippets using org.hisp.dhis.calendar.Calendar.fromIso (Showing top 20 results out of 315)

origin: dhis2/dhis2-core

/**
 * Returns an instance of a DateUnit.
 *
 * @param date date of calendar in local calendar
 * @return an instance of a Calendar without any time of day.
 */
public static DateTimeUnit createLocalDateUnitInstance( Date date, org.hisp.dhis.calendar.Calendar calendar )
{
  return calendar.fromIso( date );
}
origin: dhis2/dhis2-core

/**
 * Sets the current time.
 *
 * @param date the date to base time on.
 */
public Cal set( Date date )
{
  dateTimeUnit = getCalendar().fromIso( DateTimeUnit.fromJdkDate( date ) );
  return this;
}
origin: dhis2/dhis2-core

/**
 * Returns a list of calendar specific period identifiers for the given collection of
 * periods and calendar.
 *
 * @param periods  the list of periods.
 * @param calendar the calendar to use for generation of iso periods.
 * @return a list of iso period identifiers.
 */
public static <T extends IdentifiableObject> List<String> getLocalPeriodIdentifiers( Collection<T> periods, Calendar calendar )
{
  List<String> localIdentifiers = new ArrayList<>();
  for ( IdentifiableObject object : periods )
  {
    Period period = (Period) object;
    DateTimeUnit dateTimeUnit = calendar.fromIso( period.getStartDate() );
    localIdentifiers.add( period.getPeriodType().getIsoDate( dateTimeUnit ) );
  }
  return localIdentifiers;
}
origin: dhis2/dhis2-core

public Period createPeriod( Calendar cal )
{
  org.hisp.dhis.calendar.Calendar calendar = getCalendar();
  return createPeriod( calendar.fromIso( DateTimeUnit.fromJdkCalendar( cal ) ), calendar );
}
origin: dhis2/dhis2-core

/**
 * Returns the years which the given period spans.
 *
 * @param period the period.
 * @return a set of years.
 */
private static Set<Integer> getYears( Period period )
{
  Set<Integer> years = new HashSet<>();
  int startYear = PeriodType.getCalendar().fromIso( period.getStartDate() ).getYear();
  int endYear = PeriodType.getCalendar().fromIso( period.getEndDate() ).getYear();
  while ( startYear <= endYear )
  {
    years.add( startYear );
    startYear++;
  }
  return years;
}
origin: dhis2/dhis2-core

@Override
public Date getRewindedDate( Date date, Integer rewindedPeriods )
{
  Calendar cal = getCalendar();
  date = date != null ? date : new Date();
  rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
  DateTimeUnit dateTimeUnit = cal.fromIso( DateTimeUnit.fromJdkDate( date ) );
  dateTimeUnit = cal.minusMonths( dateTimeUnit, rewindedPeriods );
  return cal.toIso( dateTimeUnit ).toJdkDate();
}
origin: dhis2/dhis2-core

  @Override
  public Date getRewindedDate( Date date, Integer rewindedPeriods )
  {
    Calendar cal = getCalendar();

    date = date != null ? date : new Date();
    rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;

    DateTimeUnit dateTimeUnit = cal.fromIso( DateTimeUnit.fromJdkDate( date ) );
    dateTimeUnit = cal.minusMonths( dateTimeUnit, rewindedPeriods );

    return cal.toIso( dateTimeUnit ).toJdkDate();
  }
}
origin: dhis2/dhis2-core

final int year = PeriodType.getCalendar().fromIso( period.getStartDate() ).getYear();
origin: dhis2/dhis2-core

@Override
public String getIsoDate( DateTimeUnit dateTimeUnit, Calendar calendar )
{
  int month = dateTimeUnit.getMonth();
  if ( dateTimeUnit.isIso8601() )
  {
    month = calendar.fromIso( dateTimeUnit ).getMonth();
  }
  switch ( month )
  {
    case 1:
      return dateTimeUnit.getYear() + "S1";
    case 7:
      return dateTimeUnit.getYear() + "S2";
    default:
      throw new IllegalArgumentException( String.format( "Month not valid [1,7]: %d", month ) );
  }
}
origin: dhis2/dhis2-core

/**
 * Creates a valid Period based on the given date. E.g. the given date is
 * February 10. 2007, a monthly PeriodType should return February 2007. This
 * method is intended for use in situations where a huge number of of periods
 * will be generated and its desirable to re-use the calendar.
 *
 * @param date     the date which is contained by the created period.
 * @param calendar the calendar implementation to use.
 * @return the valid Period based on the given date
 */
public Period createPeriod( final Date date, final org.hisp.dhis.calendar.Calendar calendar )
{
  return PERIOD_CACHE.get( getCacheKey( calendar, date ), p -> createPeriod( calendar.fromIso( DateTimeUnit.fromJdkDate( date ) ), calendar ) );
}
origin: dhis2/dhis2-core

@Override
public Optional<List<Object[]>> getPopulateTempTableContent()
{
  List<PeriodType> periodTypes = PeriodType.getAvailablePeriodTypes();
  List<Object[]> batchArgs = new ArrayList<>();
  Date startDate = new Cal( 1975, 1, 1, true ).time(); //TODO
  Date endDate = new Cal( 2025, 1, 1, true ).time();
  
  List<Period> dailyPeriods = new DailyPeriodType().generatePeriods( startDate, endDate );
  List<Date> days = new UniqueArrayList<>( dailyPeriods.stream().map( Period::getStartDate ).collect( Collectors.toList() ) );
  Calendar calendar = PeriodType.getCalendar();
  for ( Date day : days )
  {
    List<Object> values = new ArrayList<>();
    final int year = PeriodType.getCalendar().fromIso( day ).getYear();
    
    values.add( day );
    values.add( year );
    for ( PeriodType periodType : periodTypes )
    {
      values.add( periodType.createPeriod( day, calendar ).getIsoDate() );
    }
    batchArgs.add( values.toArray() );
  }
  return Optional.of( batchArgs );
}
origin: dhis2/dhis2-core

@Override
public String getIsoDate( DateTimeUnit dateTimeUnit, Calendar calendar )
{
  int month = dateTimeUnit.getMonth();
  if ( dateTimeUnit.isIso8601() )
  {
    month = calendar.fromIso( dateTimeUnit ).getMonth();
  }
  switch ( month )
  {
    case 11:
      return dateTimeUnit.getYear() + 1 + "NovS1";
    case 5:
      return dateTimeUnit.getYear() + "NovS2";
    default:
      throw new IllegalArgumentException( "Month not valid [11,5]" );
  }
}
origin: dhis2/dhis2-core

@Override
public String getIsoDate( DateTimeUnit dateTimeUnit, Calendar calendar )
{
  int month = dateTimeUnit.getMonth();
  if ( dateTimeUnit.isIso8601() )
  {
    month = calendar.fromIso( dateTimeUnit ).getMonth();
  }
  switch ( month )
  {
    case 4:
      return dateTimeUnit.getYear() + "AprilS1";
    case 10:
      return dateTimeUnit.getYear() + "AprilS2";
    default:
      throw new IllegalArgumentException( "Month not valid [4,10]" );
  }
}
origin: dhis2/dhis2-core

/**
 * Returns a local period identifier for a specific period / calendar.
 *
 * @param period   the list of periods.
 * @param calendar the calendar to use for generation of iso periods.
 * @return Period identifier based on given calendar
 */
public static String getLocalPeriodIdentifier( Period period, Calendar calendar )
{
  if ( calendar.isIso8601() )
  {
    return period.getIsoDate();
  }
  return period.getPeriodType().getIsoDate( calendar.fromIso( period.getStartDate() ) );
}

origin: dhis2/dhis2-core

/**
 * Generates bi-weekly Periods for the whole year in which the given Period's
 * startDate exists.
 */
@Override
public List<Period> generatePeriods( DateTimeUnit start )
{
  Calendar calendar = getCalendar();
  List<Period> periods = new ArrayList<>();
  DateTimeUnit date = adjustToStartOfBiWeek( start, calendar );
  date = adjustToStartOfBiWeek( calendar.fromIso( date.getYear(), 1, 1 ), calendar );
  for ( int i = 0; i < calendar.weeksInYear( start.getYear() ) / 2; i++ )
  {
    periods.add( createPeriod( date, calendar ) );
    date = calendar.plusWeeks( date, 2 );
  }
  return periods;
}
origin: dhis2/dhis2-core

dateString = calendar.formattedDate( calendar.fromIso( date ) );
origin: dhis2/dhis2-core

@Override
public String getIsoDate( DateTimeUnit dateTimeUnit, Calendar calendar )
{
  DateTimeUnit newUnit = dateTimeUnit;
  
  if ( !calendar.name().equals( ISO_CALENDAR_NAME ) && newUnit.isIso8601() )
  {
    newUnit = calendar.fromIso( newUnit );
  }
  switch ( newUnit.getMonth() )
  {
    case 1:
      return newUnit.getYear() + "Q1";
    case 4:
      return newUnit.getYear() + "Q2";
    case 7:
      return newUnit.getYear() + "Q3";
    case 10:
      return newUnit.getYear() + "Q4";
    default:
      throw new IllegalArgumentException( "Month not valid [1,4,7,10], was given " + dateTimeUnit.getMonth() );
  }
}
origin: dhis2/dhis2-core

Date periodEndDate = period.getEndDate();
DateTimeUnit start = PeriodType.getCalendar().fromIso( periodStartDate );
DateTimeUnit end = PeriodType.getCalendar().fromIso( periodEndDate );
origin: dhis2/dhis2-core

DateTimeUnit dateTimeUnit = calendar.fromIso( period.getStartDate() );
origin: dhis2/dhis2-core

DateTimeUnit dateTimeUnit = calendar.fromIso( period.getStartDate() );
String isoDate = period.getPeriodType().getIsoDate( dateTimeUnit );
map.put( isoDate, new MetadataItem( period.getDisplayName(), includeMetadataDetails ? period : null ) );
org.hisp.dhis.calendarCalendarfromIso

Javadoc

Convert from ISO 8601 to local DateUnit.

Popular methods of Calendar

  • isIso8601
    Is this calendar based on ISO 8601 (Iso8601 / Gregorian)
  • formattedDate
    Formats dateUnit using dateFormat
  • minusYears
    Returns a new dateUnit with specified number of years subtracted
  • name
    Name of this calendar.
  • today
    Gets current date as local DateUnit
  • daysInMonth
    Gets the number of days in a calendar year/month.
  • daysInWeek
    Gets the number of days in a calendar week.
  • isValid
    Is DateTimeUnit valid for this calendar.
  • isoStartOfYear
    Get start of year as month/day, important especially for Nepali calendar
  • isoWeek
    Gets week number using local DateUnit, week number is calculated based on ISO 8601 week numbers
  • minusDays
    Returns a new dateUnit with specified number of days subtracted
  • minusMonths
    Returns a new dateUnit with specified number of months subtracted
  • minusDays,
  • minusMonths,
  • minusWeeks,
  • monthsInYear,
  • plusDays,
  • plusMonths,
  • plusWeeks,
  • plusYears,
  • setDateFormat

Popular in Java

  • Parsing JSON documents to java classes using gson
  • setContentView (Activity)
  • runOnUiThread (Activity)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • String (java.lang)
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • JTextField (javax.swing)
  • Logger (org.slf4j)
    The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that loggin
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now